How to FULLY Automate Reports using R
Using parameters in Quarto to automate the production of customized reports
Would you like to know how to automate reports with customized parameters using the R programming language?
In this video you will learn how to:
create reports using Quarto in RStudio.
add specific parameters / variables to fully customize your reports.
use an R script to produce all your reports automatically.
Watch the video now:
Why Automated Reports Are So Useful
Posit, the company who developed and maintains Quarto, just released a new article showing how to use parameters in Quarto to automate Word documents, PowerPoints, PDFs, and HTML pages very easily for full automation.
We’ll go through this article showing you how easy it is now to have specific parameters like years, months, weeks for example for the timeline, or by name, by companies, by regions - whatever you need.
Concrete Example
Here is a concrete example: if you want to create reports for different years, you can choose a year parameters and you can create different Word documents or PDFs based on this unique variable.
As Quarto supports either R or Python, we will concentrate on R programming.
Setting Up Your First Parametric Report
Let’s open RStudio now. In RStudio, you just go to File > New File or click on the new file button and simply click on “Quarto Document”. This will open a window with a title that will be the title of your document, the author (Felix Analytix), and you can choose HTML, PDF, or Word format. Let’s go for Word here.
Here’s our basic Quarto template with parameters:
---
title: "How to Fully Automate Reports using R programming"
author: "Felix Analytix"
format: docx
params:
name: "Luke Skywalker"
year: "2024"
---
Hello `{r} params$name`!
## Sub section for `{r} params$year`
Hello !library(dplyr)
starwars |>
dplyr::filter(name == params$name)Let’s break down what’s happening here:
We add two parameters in our YAML header:
nameandyearWe use the
starwarsdataset from thedplyrpackage, which contains information about Star Wars charactersWe can reference parameters inline using
params$nameorparams$yearWe filter our dataset to show only information for the specified character
When you click “Render”, you’ll get a Word document that says “Hello Luke Skywalker!” and shows the filtered dataset containing only Luke Skywalker’s information.
You can change the parameter values to get different reports for each Star Wars character. For example, changing the name to “C-3PO” will create a report specifically for that character.
Full Automation: Creating Multiple Reports
Now for the most exciting part - full automation! Our goal is to create different reports for each character name with a specific greeting and filtered dataset.
For this, we need to create another R script that will generate all reports automatically:
library(dplyr)
library(purrr)
data <- expand.grid(
name = unique(starwars$name),
year = "2024",
stringsAsFactors = FALSE)
df <- data |>
dplyr::mutate(
output_format = "docx", # Output format (html, word, etc.)
output_file = paste( # Output file name
name, year, "report.docx",
sep = "_"
),
execute_params = purrr::map2( # Named list of parameters
year, name,
\(year, name) list(name = name, year = year)
)
) |>
dplyr::select(-c(name, year))
df
purrr::pwalk(
.l = df, # Dataframe to map over
.f = quarto::quarto_render, # Quarto render function
input = "20240823-automate-report.qmd", # Named arguments of .f
.progress = TRUE # Optionally, show a progress bar
)Here’s what this automation script does:
Create parameter combinations: We use
expand.grid()to create all combinations of names and yearsBuild output specifications: We specify the output format (docx) and create unique filenames for each report
Set up parameters: We create a list of parameters for each report using
purrr::map2()Generate all reports: We use
purrr::pwalk()withquarto::quarto_render()to create all reports automatically
When you run this code, you’ll see in the R console that it’s building reports for each Star Wars character. This process takes around 10 minutes depending on your system and the number of reports being generated.
Key Benefits
This automated approach offers several advantages:
Scalability: Generate hundreds or thousands of reports with minimal effort
Consistency: All reports follow the same template and formatting
Efficiency: Once set up, the entire process runs automatically
Flexibility: Easy to modify parameters and add new variables
While this was already possible with R Markdown, Quarto makes it even more streamlined and integrates better with other programming languages.
Conclusion
I hope this tutorial was useful! I wanted to share this amazing new feature of Quarto that makes report automation incredibly straightforward. Whether you’re creating reports for different time periods, clients, regions, or any other parameter, this approach can save you countless hours of manual work.
The combination of Quarto’s parametric reports with R’s data manipulation capabilities provides a powerful framework for automated reporting that scales beautifully with your needs.

