Create code chunks
Quarto visual mode in R studio
When working with Quarto documents, you can switch between a “Source”and a “Visual” mode in R studio. In ths Visual mode, you can click on “Insert” –> “Executable Cell” –> “R”. Here you also see the various other programming languages listed that are supported by Quarto.

When creating a chunk like this, a block appears in your .qmd file where you can directly type your R code.
Although you can find everything you need to create your full .qmd file in the “Visual” mode with the guided user interface, we recommend to work in “Source” mode as much as possible.
Quarto source mode in R studio

In source mode, you can create a code chunk by typing three backticks followed by the language in curly braces—for example, ```{r} for R, and then closing the chunk with another set of three backticks. Everything between these fences will be treated as executable code when the document is rendered.
As you develop a Quarto document, it’s good practice to regularly check that it still executes correctly. The most direct way to do this is by rendering the document frequently. Rendering runs all code chunks in sequence, ensuring that each one can be executed successfully and that objects or results are correctly available when needed. You can render the document by clicking the Render button in RStudio, using the keyboard shortcut Ctrl + Shift + K (Windows/Linux) or Cmd + Shift + K (Mac), or by running quarto render yourfile.qmd in the terminal.
If the document executes without errors, the rendered output (HTML, PDF, or Word) will be updated. If an error occurs, Quarto will stop rendering and display a message pointing to the problematic chunk. Reading these messages carefully helps identify where code might rely on outdated objects or missing packages. Running code chunks individually in RStudio (by clicking the green play icon at the top right of each chunk or pressing Ctrl + Shift + Enter) is another useful way to test smaller sections before rendering the entire document. By checking execution regularly, you can catch issues early and ensure your document remains fully reproducible from start to finish.
Labelling chunks
Each R code chunk in a Quarto document can be given a label, which is specified immediately after the opening {r} in the chunk header. For example: ```#| label: data-summary.
The label data-summary uniquely identifies this chunk. Labels serve several important purposes. They make your document easier to navigate, help organize the flow of your analysis, and are used internally by Quarto for features such as caching, error reporting, and cross-referencing. For instance, if a rendering error occurs, Quarto reports it using the chunk label, making it straightforward to locate the source of the problem. Labels are also used to name figures or tables generated by that chunk, which ensures consistent and readable file names in your output directory.
As a matter of good practice, chunk labels should be unique, short but descriptive, and use only lowercase letters, numbers, and hyphens or underscores (avoid spaces or special characters). A clear naming convention—such as data-load, model-fit, or plot-results—helps maintain readability and reproducibility, especially in longer documents. Consistent labeling not only improves your own workflow but also supports collaboration, as others can easily follow the structure and dependencies of your analysis.