Skip to content
Module 11 of 1250 min readBeginner

Reporting with R Markdown / Quarto

How to turn an analysis into a reproducible document. YAML headers, code chunks, parameters.

92%

Listen along

Read “Reporting with R Markdown / Quarto” aloud

Plays in your browser using on-device text-to-speech — nothing leaves the page.

Learning objectives

By the end of this module, you should be able to:

  • 01Author reproducible reports in R Markdown and Quarto
  • 02Configure code-chunk options (echo, message, warning, fig.width) for clean output
  • 03Use inline R expressions to embed computed values directly in narrative text
  • 04Decide between Quarto for static reports and Shiny for interactive applications

An analysis isn't done until it's communicated. R Markdown and Quarto are R's reproducible reporting tools — a single document combining narrative, code, and output, rendered to HTML, PDF, or Word.

R Markdown — the original

r
---
title: "Kenyan banking spread analysis"
author: "You"
output: html_document
---
## Introduction
We analyse 21 months of commercial bank lending rates...
```{r}
library(dplyr)
library(ggplot2)
bankrates |>
mutate(spread = lending_rate - deposit_rate) |>
summarise(mean_spread = mean(spread))
```
The mean spread is shown above.

The .Rmd file mixes Markdown narrative with code chunks. When you knit (Ctrl+Shift+K in RStudio), R runs every chunk in order and produces the rendered output document.

Quarto — the modern successor

Quarto is R Markdown's successor, by the same team. It supports R, Python, and Julia equally; it has more output formats; and it ships with a smarter default theme. The syntax is nearly identical (.qmd files); migration is trivial. New projects should default to Quarto.

Code chunks — options

r
```{r my-chunk, echo = FALSE, message = FALSE, warning = FALSE, fig.width = 8}
# echo = FALSE: don't show the code, only the output
# message/warning = FALSE: suppress noise
# fig.width: chart dimensions
```

Parameterised reports

You can parameterise a Quarto/Rmd document — pass values in via YAML or the command line — to produce country-specific or period-specific versions of the same report. Useful for monthly economic updates.

When to use Quarto vs a Shiny app

Quarto: a static rendered document, refreshed on a schedule. Shiny: interactive — sliders and dropdowns drive a live recomputation. Quarto for reports; Shiny for tools.

Reproducibility is the point

The whole reason you're using R Markdown / Quarto is so that next year, when someone asks 'where did this number come from?', you can re-knit the same document and get the same answer. Avoid hard-coded values in narrative — always reference inline R: the spread is `r round(mean_spread, 3)`%.

Exercise

Write a YAML header for a Quarto document titled 'Pension allocation analysis' that outputs HTML.

Key takeaways

  • Quarto is R Markdown's successor — supports R, Python, Julia, and has better defaults
  • Inline R: 'The mean spread was `r round(mean_spread, 3)`%' — never hard-code numbers in narrative
  • echo = FALSE hides the code; message/warning = FALSE suppresses noise; both useful in finished reports
  • Reproducibility is the point: a year-old analysis should re-knit and produce the same numbers

Further reading

  1. 01

    R Markdown: The Definitive Guide

    Yihui Xie, J.J. Allaire & Garrett Grolemund · CRC Press · 2018

  2. 02
  3. 03

    Reproducible Research with R and RStudio (3rd Edition)

    Christopher Gandrud · CRC Press · 2020

Loading progress…
LeadAfrikPublic Economics Hub