Parameters & Reports in Quarto
Suppose you need the same report for twelve sales regions, or for every month of the year. You don’t write it twelve times — you write it once with parameters, then render it repeatedly with different values. This is where reproducible reporting pays for itself.
Declaring parameters
Add a params: block to the YAML header. Each entry is a name and a default value:
---
title: "Regional Sales Report"
format: html
params:
region: "West"
year: 2024
---Using parameters in code
Inside the document, the values are available as a list called params. You reach a value with params$name:
```{r}
#| echo: false
paste("Report for", params$region, "in", params$year)
```Anywhere the report mentions the region or year, you read it from params instead of typing it — so a single change to the header re-flavours the whole document.
Rendering with different values
Override the defaults at render time, no editing required:
quarto render report.qmd -P region:"East" -P year:2025Loop over that command (in a shell script or with R’s quarto::quarto_render()) and you generate a whole stack of tailored reports from one source. Our post one template, fifty reports shows the full pattern.
Try it
params is just a list. Complete the code below so it prints the region — replace the blank with the right name, then press Run Code:
You reach a value in a list with list$name. The name you want is region.
Solution
params <- list(region = "West", year = 2024)
print(params$region)params$region returns "West". In a real report, params comes from the YAML header instead of being written by hand.
Next: Publishing → — render to HTML, PDF and Word, and put your report online.