Quarto

2024-09-09

The header

  • Start a new empty document.

  • At the top you see:


---
title: "Untitled"
---


  • The things between the --- is the YAML header.

  • You will see it used throughout the Quarto guide.

Text formating

*italics* or _italics_ = italics

**bold** = bold

***bold italics*** = bold italics

~~strikethrough~~ = strikethrough

`code` = code

Text formating

This:

```
line 1
line 2
```

shows code chunks:

line 1
line 2

Headings

You can start sections and subsections like this:

# Header 1

## Header 2

### Header 3

Images

![My caption](https://datasciencedojo.com/wp-content/uploads/11-1.jpg)

Shows the plot and caption:

My caption

The image can also be a local file.

Lists

Bullets:

-   bullet 1
    -   sub-bullet 1
    -   sub-bullet 2
-   bullet 2

Looks like this:

  • bullet 1
    • sub-bullet 1
    • sub-bullet 2
  • bullet 2

Lists

Ordered list:

1.  Item 1
2.  Item 2

Looks like this:

  1. Item 1
  2. Item 2

Equations

Note

If you are going to write technical report, you definitely want to learn LaTeX.

Once you learn LaTeX you will never want to use an equation editor again.

There are many online tutorials, like this one.

ChatGPT is great at LaTeX

Equations

Examples:

  • Inline: $Y_i = \beta_0 + \beta_1 x_i + \varepsilon_i$ looks like this \(Y_i = \beta_0 + \beta_1 x_i + \varepsilon_i\)

  • Display math:

$$
\mathbf{Y} = \mathbf{X\beta} + \mathbf{\varepsilon}
$$

looks like this:

\[ \mathbf{Y} = \mathbf{X\beta} + \mathbf{\varepsilon} \]

Computations

  • The main reason we use Quarto is because we can include code and execute the code when compiling the document.

  • In R we refer to them as R chunks.

  • This applies to plots as well; the plot will be placed in that position.

Note

To add your own R chunks, you can type the characters above quickly with the key binding command-option-I on the Mac and Ctrl-Alt-I on Windows.

Computations

We can write something like this:

```{r}
x <- 1
y <- 2
x + y
```

Computations

It look slike this:

x <- 1
y <- 2
x + y
[1] 3

Note that it was evaluated and the result is shown.

Computations

  • By default, the code and result will show up as well.

  • You can send arguments to control the behavior with |#

  • For example, to avoid showing code in the final document, you can use the argument echo: FALSE.

```{r}
#| echo: false
x <- 1
y <- 2
x + y
```

Computations

  • There are many options (auto-complete shows them).

  • For example, to avoid the the code running you can use eval: FALSE.

  • To avoid showing warnings warning: FALSE, to avoid showing messages message: FALSE.

Note

If you want to apply an option globally, these can be set globally in the header.

execute:
  echo: false

Computations

  • We recommend getting into the habit of labeling code chunks:
```{r}
#| label: one-plus-two
x <- 1
y <- 2
x + y
```
  • Helps with debugging

  • Gives meaningful names to generated images.

More on markdown

There is a lot more you can do with R markdown. We highly recommend you continue learning as you gain more experience writing reports in R. There are many free resources on the internet including:

quarto render

  • RStudio provides the Render button that makes it easier to compile the document.

  • You can also type quarto render filename.qmd on the command line. This offers many options.

  • You can produce html, pdf, or word documents.

  • You can specify the default in the YAML header using: format: html, format: pdf,format: docx, or format: gfm (gfm stands for GitHub flavored markdown, a convenient way to share your reports).