Getting Started with Quarto
Quarto is an open-source publishing system that lets you create documents combining code, output, and narrative text. It supports R, Python, and Julia, and can produce HTML pages, PDF documents, Word files, presentations, dashboards, and websites from a single source file. Quarto is the successor to R Markdown, which pioneered this approach in the R ecosystem. If you encounter older tutorials or course materials that reference R Markdown (.Rmd files), the concepts are nearly identical — Quarto uses the same code chunk syntax and Markdown formatting, with an updated YAML header and additional features.
To create a new Quarto document in RStudio, go to File → New File → Quarto Document…, enter a title and author name, choose an output format (HTML, PDF, or Word), and click Create. RStudio creates a .qmd file with a starter template that you can immediately edit and render.
Every Quarto document has three parts: a YAML header that specifies metadata, Markdown text that provides narrative, and code chunks that contain executable R code.
YAML Header
The YAML header appears at the top of the file, enclosed between --- markers. It specifies the document’s title, author, date, and output format:
Common YAML options:
| Option | Purpose | Example |
|---|---|---|
title |
Document title | title: "My Report" |
author |
Author name | author: "Jane Smith" |
date |
Date (or today for current date) |
date: today |
format |
Output format | format: html, format: pdf, format: docx |
You can specify multiple formats or add format-specific options:
Code Chunks
Code chunks contain R code that is executed when the document is rendered. They are enclosed between ```{r} and ``` markers:
When rendered, the code runs and its output (tables, plots, printed text) appears in the finished document directly below the code. You can include as many code chunks as needed, interspersed with narrative text.