Reproducible Analysis Reports with Quarto
If you have ever struggled with keeping your analysis, code, and narrative in sync, Quarto is about to make your life much easier. It is a publishing system that lets you combine markdown, code, and output into beautiful documents that anyone can reproduce.
What is Quarto?
Quarto is an open-source scientific and technical publishing system. Think of it as the evolution of R Markdown—same idea (code plus narrative equals document), but with a cleaner design, better defaults, and support for Python, R, Julia, and Observable JavaScript all in one project.
The key advantage for R users is that Quarto handles code chunks the same way R Markdown did, but with improved rendering and a more consistent syntax. Your existing R knowledge transfers directly.
Prerequisites
Before you start, make sure you have:
- R installed (version 4.0 or later)
- RStudio (optional but recommended) or a code editor
- Quarto CLI installed on your system
You can check if Quarto is installed by running:
quarto --version
If it is not installed, grab the installer from quarto.org.
Setting Up a Quarto Document
Creating a new Quarto project is straightforward. In RStudio, go to File > New File > Quarto Document. You will see options to create an HTML, PDF, or Word document. Start with HTML—it is the easiest to preview and debug.
A basic Quarto document starts with a YAML header:
---
title: "My Analysis"
format: html
---
Below the YAML, you write regular markdown. Here is a minimal example that includes an R code chunk:
# This is a simple R code chunk
message("Hello from Quarto!")
The {r} syntax starts an R code chunk. The lines after are chunk options—echo = shows the code in the output, and fig.cap gives the chunk a name.
Including R Code Chunks
Code chunks are where the magic happens. You can execute R code directly in your document, and the results appear inline or as figures. Here is a more complete example with data manipulation:
library(dplyr)
# Create sample data
data <- tibble(
name = c("Alice", "Bob", "Charlie"),
age = c(25, 30, 35),
score = c(85, 92, 78)
)
# Transform the data
result <- data %>%
mutate(score_pct = score / 100)
print(result)
Quarto executes the code when you render the document and captures the output automatically. This means your document is always up to date with your latest analysis—no copy-pasting required.
Adding Data Visualizations
Visualizations go in code chunks too. Quarto automatically captures ggplot2 plots and includes them in your output:
library(ggplot2)
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point() +
labs(
title = "Car Weight vs. Miles Per Gallon",
x = "Weight (1000 lbs)",
y = "Miles per Gallon"
)
Key chunk options here:
echo = FALSEhides the R code (only the plot shows)fig.capadds a caption below the figure
You can also control figure dimensions, alignment, and whether to include the code in the output.
Rendering to HTML or PDF
When you are ready to publish, render your document with the Quarto CLI:
quarto render my-document.qmd
This creates my-document.html (or .pdf if you changed the format). For PDF output, you will need a LaTeX distribution installed—Quarto can use TinyTeX, which is easy to set up:
quarto install tinytex
RStudio users can also click the Render button in the toolbar for a one-click preview.
Best Practices for Reproducibility
A reproducible report is one that anyone (including future you) can re-run from scratch. Here is how to make that happen:
- Seed your random numbers — If your analysis involves randomness, set a seed:
set.seed(123) # Makes results reproducible
-
Use relative paths — Keep your data files in the same project folder so the document works anywhere.
-
Document dependencies — Include a chunk that prints your R environment:
sessionInfo()
-
Clean up intermediate files — Do not leave temporary objects hanging around between chunks unless necessary.
-
Test your document — Render it on a fresh machine or in a container to catch missing dependencies.
Conclusion
Quarto gives you a clean, powerful way to combine analysis and narrative into shareable documents. Start with HTML to iterate quickly, then switch to PDF for final reports. The key is keeping your code in the document from day one—it is the easiest way to ensure your results are always reproducible.
The workflow takes a bit of adjustment if you are used to running R scripts separately, but the payoff is worth it. Your colleagues will thank you when they can reproduce your analysis with a single command.
See Also
quarto-getting-started— Getting Started with Quarto tutorialrmarkdown-guide— R Markdown: Reproducible Reports guide