6.3 Code chunks

Both R markdown and Quarto can use the following ways to specify chunk options:

Use tag=value in the chunk header ```{r}.

```{r my-label, fig.cap = caption}

# R code
```

Alternatively, you can write chunk options in the body of a code chunk after #|, e.g.,

```{r}
#| label: fig-my-label
#| fig-cap: caption 

# R code
```

tag: value is the YAML syntax.

Options format:

  • space after #| and colon :
  • Logical values in YAML can be any of: true/false, yes/no, and on/off.
    • They all equivalent to TRUE/FALSE (uppercase) in Rmd.
    • Note that TRUE/FALSE need to be in uppercase in Rmd.

Note that Quarto accepts Rmd’s way of specifying chunk options. The difference is that Quarto’s label for figures must start with fig-, while Rmd accepts any labels.

```{r label = "fig-my-label", fig.cap = caption}

# R code
```

❗️ Note that NOT all Rmd chunk options are supported in Quarto. See Quarto Chunk Options for all available options.

Quarto chunk options available for customizing output include:

Option Description
eval Evaluate the code chunk (if false, just echos the code into the output).
echo Include the source code in output
output\(^{[1]}\) Include the results of executing the code in the output (true, false, or asis to indicate that the output is raw markdown and should not have any of Quarto’s standard enclosing markdown).
warning Include warnings in the output.
error Include errors in the output (note that this implies that errors executing code will not halt processing of the document).
include Catch all for preventing any output (code or results) from being included (e.g. include: falsesuppresses all output from the code block).
renderings Specify rendering names for the plot or table outputs of the cell, e.g. [light, dark]

\(^{[1]}\) output is similar to results in Rmd. You cannot use results='hide' in Quarto, use output: false instead.