R Markdown parameterized reports let you create dynamic, reusable documents whose content changes based on user-supplied parameters.
R Markdown parameterized reports transform static documents into dynamic, customizable assets that can be re-rendered for multiple audiences or time periods—all from a single source file. Whether you need monthly KPI decks, client-specific analyses, or A/B test summaries, parameterization lets you generate tailored outputs without rewriting code.
This tutorial explains how parameters work in R Markdown, why they matter, and how to master them with practical examples, best practices, and common pitfalls.
In an .Rmd
file, parameters (params
) are variables declared in the YAML header that become available inside the document’s R code, inline text, and code chunks. When you render the report, you supply values for those parameters; R Markdown swaps them in, runs the code, and produces a version of the document specific to those inputs.
cron
or GitHub Actions) to generate reports for different regions, dates, or products..Rmd
File---
output: html_document
title: "Sales Overview"
params:
region: "north_america"
start_date: !r Sys.Date() - 30
end_date: !r Sys.Date()
---
Key points:
region
, start_date
, and end_date
.!r
) evaluate when the document is rendered, enabling dynamic defaults.# access in code chunks
library(dplyr)
filter(sales, region == params$region &
date >= params$start_date &
date <= params$end_date)
You can also reference them inline:
“This report covers `r params$region`
sales from `r params$start_date`
to `r params$end_date`
.”
rmarkdown::render()
rmarkdown::render("sales_report.Rmd", params = list(
region = "emea",
start_date = as.Date("2023-01-01"),
end_date = as.Date("2023-01-31")
))
Click Render; RStudio pops up a GUI where users enter parameter values.
Connect lets viewers launch on-demand versions through a web form. Shiny apps can call rmarkdown::render()
behind the scenes.
churn_template.Rmd
) with params: month
, product_line
.generate_churn_reports.R
) that loops over months & product lines, calling render()
each time and saving PDFs to reports/<product>/
.targets
or drake
pipeline packages to avoid recomputing heavy steps.Why wrong: Defeats reusability; any change requires editing the template.
Fix: Move the values to the YAML params
block and reference params$*
in code.
Why wrong: Passing a string when code expects Date
triggers errors.
Fix: Coerce inside render()
or use assertions like stopifnot(lubridate::is.Date(params$start_date))
.
Why wrong: Users don’t know valid values.
Fix: Include an Inputs section at the top of your report or README listing allowed choices and formats.
Parameterization works with any format—HTML, PDF, Word. Use output: bookdown::html_document2
for paged HTML, or output: powerpoint_presentation
for slide decks.
Define multiple named sets in YAML to batch render:
params:
region: !r NA
sets:
- id: "apac"
region: "apac"
- id: "emea"
region: "emea"
Then loop through params$sets
inside a script.
Use runtime: shiny
plus shiny::selectInput()
to let users pick parameter values in real time.
Parameterized reports slot neatly into CI/CD pipelines. Store the template in Git, test rendering on pull requests, and deploy to Posit Connect or AWS Lambda for on-demand generation. The paradigm aligns with DRY (Don’t Repeat Yourself) principles popular in modern data engineering.
params
in YAML, reference them as params$*
.Explore the rmarkdown
and knitr
vignettes, integrate with pipeline tools, and experiment with Shiny-powered inputs to build powerful self-service analytics workflows.
Modern data teams must deliver tailored insights rapidly. Parameterized R Markdown reports enable a single, version-controlled template to serve multiple stakeholders by swapping in different data slices at render time. This reduces duplication, simplifies automation, and enforces consistency across recurring deliverables like KPI decks, client dashboards, or compliance summaries—critical tasks in data engineering and analytics workflows.
It’s an R Markdown document that defines variables (parameters) in its YAML header. When you render the file, you supply values for those variables, enabling the same template to output different results without changing the code.
Use rmarkdown::render("file.Rmd", params = list(key = value))
. The list keys must match the parameter names declared in the YAML header.
Yes. RStudio displays a GUI input form, Posit Connect offers on-demand parameter forms, and adding runtime: shiny
turns the document into an interactive Shiny app.
Galaxy’s SQL editor parameterizes raw database queries, whereas R Markdown parameters drive entire documents that may include SQL, R code, narrative, and visuals. Both concepts reduce repetition, but R Markdown targets document generation rather than interactive query editing.