Lesson 22 / 25

Reproducible Reports with Quarto and R Markdown

Combine code, results and narrative into reproducible documents.

Analysis that rebuilds itself

A reproducible report mixes narrative text, code and its results in one document, so rerunning it regenerates every number, table and chart from the raw data. R Markdown (.Rmd) pioneered this in R; Quarto (.qmd), its multi-language successor from Posit, works with R, Python and Julia and renders to HTML, PDF, Word, slides, websites and books. A document has a YAML header (title, author, format and options), Markdown text, and code chunks with options such as echo: false (hide code), warning: false and fig-cap for captions. Inline code inserts computed values into sentences, so a sentence such as "revenue grew by 12%" is always correct. Parameters let one template produce reports per city or per month. Render with the Render button or quarto render report.qmd. Reproducible reports eliminate copy-paste errors between analysis and document, make reviews possible and let you update monthly reports in minutes.

Code, results and narrative in one document

A single source file renders to HTML, PDF or slides with fresh results every time.

A document icon split into text lines and code blocks, with arrows to three output icons: a web page, a PDF and a slide.
Figure 8.1 — Rendering a Quarto document to several formats.

A parameterised Quarto report

Inline values and chunks keep numbers in sync with the data.

---
title: "Monthly sales report"
format:
  html:
    toc: true
params:
  city: "Pune"
  month: "2026-09"
execute:
  echo: false
  warning: false
---

```{r}
library(dplyr)
sales <- readr::read_rds("data/sales_clean.rds") |>
  filter(city == params$city, format(order_date, "%Y-%m") == params$month)
revenue <- sum(sales$amount_inr)
```

In `r params$month`, `r params$city` recorded `r nrow(sales)` orders
with revenue of Rs `r format(revenue, big.mark = ",")`.

```{r}
#| fig-cap: "Daily revenue"
sales |>
  summarise(revenue = sum(amount_inr), .by = order_date) |>
  ggplot2::ggplot(ggplot2::aes(order_date, revenue)) + ggplot2::geom_col()
```

# render one report per city:
# quarto render report.qmd -P city:Delhi -P month:2026-09

Never type numbers into reports by hand

Every number typed manually becomes wrong the moment the data changes. Inline code (r expression) keeps text and data in sync.

Quick check: What is the main benefit of a Quarto or R Markdown report?

  • It makes R run faster
  • It replaces databases
  • Rerunning it regenerates every result from the data, avoiding copy-paste errors
  • It only produces PDFs
Answer

Rerunning it regenerates every result from the data, avoiding copy-paste errors — Reproducible documents tie narrative and results directly to code and data.