2025 MAPOR Fall Webinar Series

Automating Repetitive Reports with Quarto
Overview
What is Quarto?
Getting started
Iterating your reports
Styling your reports
Rendering other formats
Summary
We will be using data from TidyTuesday on polling places in the United States.
Geocoded by @thedivtagguy
How to do this without…

Note
We will be using R code.
Automating Repetitive Reports with Quarto
Overview
What is Quarto?
Getting started
Iterating your reports
Styling your reports
Rendering other formats
Summary
Quarto is an open-source scientific and technical publishing system that allows you to combine text, images, code, plots, and tables in a fully-reproducible document. Quarto has support for multiple languages including R, Python, Julia, and Observable. It also works for a range of output formats such as PDFs, HTML documents, websites, presentations.
Definition by Nicola Rennie
Artwork from “Hello, Quarto” keynote by Julia Lowndes and Mine Çetinkaya-Rundel, presented at RStudio::Conf(2022). Illustrated by Allison Horst.
Automating Repetitive Reports with Quarto
Overview
What is Quarto?
Getting started
Iterating your reports
Styling your reports
Rendering other formats
Summary






.qmd extensionUse the Render button (in RStudio) or the Preview button (in Positron or VS Code) to preview documents as you edit them.


A .qmd file format with three components:
YAML: Metadata
Text: Markdown
Code: R, Python, Observable, and Julia
Weave it all together, and you have beautiful, powerful, and useful outputs!
Metadata: YAML
Metadata: YAML
Text: Markdown
report.qmd
Text: Markdown
| Markdown syntax | Output |
|---|---|
|
italics and bold |
|
superscript2 / subscript2 |
|
|
|
verbatim code |
Text: Markdown
**In this report**, we *present* a detailed overview of
[polling places](https://www.vote.org/polling-place-locator/) in various
counties across the `United States`.
Results in:
In this report, we present a detailed overview of polling places in various counties across the United States.
Code
report.qmd
---
title: "Polling Places Report - Alabama"
format: html
---
**In this report**, we *present* a detailed overview of [polling places](https://www.vote.org/polling-place-locator/) in various counties across the `United States`.
```{r}
library(tidyverse)
us_states <- states(cb = TRUE, resolution = "20m") |>
filter(NAME != "Puerto Rico")
ggplot(us_states |> filter(NAME == "Alabama")) +
geom_sf() +
geom_point(data = polling_places |> filter(state == "Alabama"),
aes(x = longitude,
y = latitude),
alpha = 0.4) +
theme_void()
```Code
report.qmd
---
title: "Polling Places Report - Alabama"
format: html
---
**In this report**, we *present* a detailed overview of [polling places](https://www.vote.org/polling-place-locator/) in various counties across the `United States`.
```{r}
library(tidyverse)
us_states <- states(cb = TRUE, resolution = "20m") |>
filter(NAME != "Puerto Rico")
ggplot(us_states |> filter(NAME == "Alabama")) +
geom_sf() +
geom_point(data = polling_places |> filter(state == "Alabama"),
aes(x = longitude,
y = latitude),
alpha = 0.4) +
theme_void()
```{}Code
Code can include optional chunk options, in YAML style, identified by #| at the beginning of the line
| Option | Description |
|---|---|
eval |
Evaluate the code chunk |
echo |
Include the source code |
warning |
Include warnings |
include |
Include code and results |
Other options: https://quarto.org/docs/computations/execution-options.html
---
title: "Polling Places Report - Alabama"
format: html
---
**In this report**, we *present* a detailed overview of [polling places](https://www.vote.org/polling-place-locator/) in various counties across the `United States`.
```{r}
#| echo: false
#| warning: false
library(tidyverse)
us_states <- states(cb = TRUE, resolution = "20m") |>
filter(NAME != "Puerto Rico")
ggplot(us_states |> filter(NAME == "Alabama")) +
geom_sf() +
geom_point(data = polling_places |> filter(state == "Alabama"),
aes(x = longitude,
y = latitude),
alpha = 0.4) +
theme_void()
```Code
Inline code executes code within Markdown
Results in:
The number of counties is 1881.
Automating Repetitive Reports with Quarto
Overview
What is Quarto?
Getting started
Iterating your reports
Styling your reports
Rendering other formats
Summary

knitr::knit_child()knitr::knit_child() allows you to break your content into smaller, modular piecesOriginal:
_template.qmd
Child document:
_template.qmd
### {{current_county}} COUNTY
* Total Polling Places: `r polling_places |> filter(state == "Alabama", county_name == "{{current_county}}") |> count()`
* Example Locations:
```{r}
polling_places |>
filter(state == "Alabama",
county_name == "{{current_county}}") |>
head(6) |>
select(name, address.x) |>
kbl(format = "markdown")
```report.qmd
```{r}
#| results: hide
counties <- polling_places |>
filter(state == "Alabama") |>
distinct(county_name) |>
pull()
expanded_child <- counties |>
map(function(county) knitr::knit_expand("../_template.qmd", current_county = county)) |>
flatten()
parsed_child <- knitr::knit_child(text = unlist(expanded_child))
```
`r parsed_child`
Parameterized Reporting with Quarto by Jadey Ryan
params in the key:value pairparams$state notation anytime there’s a hardcoded valueparams$state notation anytime there’s a hardcoded valueOriginal:
Parameterized:
Note
This includes our inline code and child _template.qmd document!
params in the YAML to rerender the report for different statesquarto render polling-places-report.qmd -P state:'California'quarto::quarto_render()Option 1:
params for each state
Option 2:
quarto::quarto_render()output_format: file type (html, revealjs, pdf, docx, etc.)output_file: file name with extensionexecute_params: named list of parameterspurrr::pwalk(dataframe, quarto_render, quarto_render_args)_parameters_render.R
library(readr)
library(dplyr)
library(quarto)
polling_places <-
readr::read_csv(here::here("data", "geocoded_polling_places.csv"))
polling_places_reports <-
polling_places |>
dplyr::distinct(state) |>
dplyr::slice_head(n = 5) |>
dplyr::mutate(
output_format = "html",
output_file = paste0(
tolower(state),
"-polling-places.html"),
execute_params = purrr::map(
state,
\(state) list(state = state))) |>
dplyr::select(output_file, execute_params)Automating Repetitive Reports with Quarto
Overview
What is Quarto?
Getting started
Iterating your reports
Styling your reports
Rendering other formats
Summary
theme under htmlsketchy quarto extension.css or .scss (Syntactically Awesome Style Sheets) file to your project/*-- scss:defaults --*/
@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz@9..144&family=Gilda+Display&display=swap');
$font-family-sans-serif: "Fraunces", sans-serif;
$presentation-heading-color: #446571;
$code-block-font-size: 0.6em;
$code-color: #5f5f5f;
$presentation-h2-font-size: 1.4em;
$link-color: #446571 !default;title-block-bannerAutomating Repetitive Reports with Quarto
Overview
What is Quarto?
Getting started
Iterating your reports
Styling your reports
Rendering other formats
Summary
pdf to the YAML to render both HTML and PDF versions of the reportAutomating Repetitive Reports with Quarto
Overview
What is Quarto?
Getting started
Iterating your reports
Styling your reports
Rendering other formats
Summary
knit_child()I hope that you enjoyed automating reports using Quarto! I’d love to see what you create:
ivelasq-automating-quarto.share.connect.posit.cloud