Quarto provides an authoring systemfor data science, combining your code, its results, and your narrative text
Unlike previous tools, Quarto is a separate command line tool run outside of R
It needs to be installed like R, rather than as an R package
No documentation via ?
Quarto
Several technologies are involved
When your document contains R code:
Quarto runs your document through knitr, which executes the R code and renders the output as markdown (.md) plus generated files (e.g. images)
Quarto then runs this markdown file through pandoc to generate the required output document(s)
Source: Wickham, Çetinkaya-Rundel, & Grolemund (2023) R for Data Science
R code chunks
Include a code chunk by surrounding code in ```
The code language is given in {} on the opening line, e.g. ```{r}
The chunk is ended by ``` on a line of its own
Arguments to the chunk include the chunk label, plus key value pairs, are given in the chunk, after ```{r}, and are prefixed with #|:
Some amazing prose that shows I'm a gifted writer should go here.And some more. Interesting aside.```{r}#| label: chunk-name#| key: value#| key: value# code here <--- this is a normal R commentfoo <-bar()```Woah! Look at that; some R code!
Chunk label
```{r}#| label: chunk-name#| key: value#| key: value# code here <--- this is a normal R commentfoo <-bar()```
The chunk label is optional but if used it must be unique
You can also use the chunk label to navigate your document in RStudio
Chunk options
Tailor how knitr outputs the results of executing the code in each chunk
Many possible options controlling output, figures, etc.
eval: false prevents the code being evaluated by R. There is no output generated but the code in the chunk is still echoed into the document
echo: false prevents the code in the chunk being output to the document. For a report, thesis, or manuscript you typically don’t want the code displayed
include: false this would allow code to be evaluated (with eval: true) but neither the code nor the output are shown in the document
message: false & warning: false prevent warnings or messages from being output into the document
results: hide hides printed (text) output, while fig.show: hide hides any plots created by the chunk
error: false causes the document to continue rendering even if the code results in an error. Not often useful but is helpful when debugging the code and the document, or when teaching and you deliberately want to raise an error
Tables
Tables are difficult to typeset — instead, create them using R data frames and then output the to the document using knitr::kable()