Skip to content
AgileLogics
6 min read

Reproducible Reports with Quarto

Prerequisites: Data visualization with ggplot2

Copying numbers and charts into a Word document by hand is slow and error-prone — and has to be redone whenever the data changes. Quarto documents mix text and code: when you render the document, the code runs and its results are inserted automatically.

(R Markdown, .Rmd, is the older format that Quarto grew from; it works almost the same way, and you'll see both.)

A Quarto document

Create one in RStudio with File → New File → Quarto Document:

---
title: "Monthly Sales Report"
author: "Ada Lovelace"
format: html
execute:
  echo: false
---

```{r}
#| label: setup
#| message: false
library(dplyr)
library(ggplot2)
sales <- readr::read_csv("data/sales.csv")
```

## Summary

We recorded `r nrow(sales)` sales, worth a total of
`r scales::dollar(sum(sales$amount))`.

```{r}
#| label: fig-monthly
#| fig-cap: "Sales by month"
sales |>
  count(month = lubridate::floor_date(date, "month"), wt = amount) |>
  ggplot(aes(month, n)) +
  geom_col()
```
  • The header (between --- lines, in YAML) sets the title and output format — html, pdf, docx, or slides such as revealjs.
  • Code chunks (```{r}) run R code; their output — tables, charts — appears in the document. #| lines set chunk options, such as hiding messages or adding a figure caption.
  • Inline code (`r nrow(sales)`) puts a computed value straight into a sentence, so the text never goes out of date.
  • echo: false hides the code itself in the finished report — useful for readers who only want results.

Click Render (or run quarto render report.qmd) to produce the report.

Why it matters

  • Reproducible — anyone can regenerate the report from the data and the document.
  • Up to date — new data? Render again, and every number and chart updates.
  • Trustworthy — the numbers in the text come from the code, not from manual copying.

Quarto also builds websites, books, and presentations, and supports Python and Julia — the same tool across languages.

Common mistakes

  • Code that works in your console but fails when rendering. Rendering starts a fresh R session, so every package, variable, and file the document needs must be loaded inside it — which is exactly what makes it reproducible.