- 3 Minutes Wednesdays
- Posts
- 3MW (Scalable Reporting with Quarto)
3MW (Scalable Reporting with Quarto)
Enjoy 3 Minute Wednesdays at no cost.
This newsletter is brought to you for free. If you want to advance your R skills and support my work at the same time, then you will like my paid offerings:
Guten Tag!
Many greetings from Munich, Germany. Parameterized reports are a powerful but often underutilized strategy for communicating data to multiple stakeholders.
Let’s say you have several departments in your organization. A common instinct is to build a dashboard where users can click around to see the data for their department.
But what if, instead, you could automatically generate one customized report per department and send those out directly? In today’s newsletter, I’ll show you how to do just that using Quarto.
Create a Basic Report Template
First, we need a sample report. We’ll use the palmerpenguins
dataset to simulate a situation where each penguin species represents a department.

This will give us a PDF output like this:

Add Parameters to the YAML Header
Here, we’ve used the "Adelie"
species to act a placeholder. Next, we have to make sure that we can easily replace the species in all instances of the text and code. To do that, we define a params
section in the YAML header:

Now, wherever we want to reference species
in the document, we use params$species
. This allows the content of the report to adapt to whatever value we plug into the parameter. It works in code chunks:

And it works in inline text as well:

Now we can try to change "Adelie"
to "Gentoo"
and re-render the report. You’ll see the whole report adjusts accordingly (most notably seen by the plot change.)

Automate Rendering for Multiple Parameters
Now the real power kicks in. We want to render one report per species, or in your real-world scenario, one report per department. To do that, we have to create a separate R script that uses the quarto_render()
function from the {quarto}
package:

This script loops over all species and renders a separate PDF report for each one.

With just a few lines of configuration and code, you now have a scalable way to generate customized PDF reports for any number of stakeholders or categories. Whether you’re reporting by department, product line, region, or team, parameterized Quarto documents make it simple and powerful.
Next week, we’re going to make that report prettier using the Typst-PDF format. And as always, if you have any questions, or just want to reach out, feel free to contact me by replying to this mail or finding me on LinkedIn or on Bluesky.
See you next week,
Albert 👋
Enjoyed this newsletter? Here are other ways I can help you:
Reply