- 3 Minutes Wednesdays
- Posts
- 3MW (Parameterized Sections With Quarto)
3MW (Parameterized Sections 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:
Or use my affiliate code “RAPP10” to get 10% off the fantastic data science courses from Athlyticz:
Guten Tag!
Many greetings from Munich, Germany. In today’s newsletter, I’ll show you how to integrate multiple parametric report sections into a single report. You see, instead of generating separate reports for each dataset, you can include multiple sections where each sections uses different data.
This could look something like this:
📄 General intro text (applies to all datasets)
🐟 Section A (Dataset A)
🐦 Section B (Dataset B)
🦋 Section C (Dataset C)
✅ General conclusion
So let’s see how to build this.
Step 1: Start with a Parametric Report
Begin with a standard parametric report, just like you normally would.
For example, let’s say you have the Quarto file from last time that generates a report for a single species. This was driven by a species
and a color
parameter in the YAML header:

This report works fine on its own, but we want to reuse the code and text within the report multiple times in a single document.
Step 2: Create a Main Quarto File
Next, create a new Quarto file that will act as the main document. This file will include first some general intro text, followed by multiple “includes” of your parametric report. For example, the document could start like this:

Step 3: Use include
Snippets
Quarto has a special feature that lets you include other Quarto files using the following syntax:

Here, this will include text and code chunks from the Quarto file species_report.qmd
. That way, you could modify your main Quarto file like this:

But if you render this now, you’ll hit an error that will say that params
is not defined. If you recall, params
is the object that we use inside the species Quarto file.
Normally, this object is created from the parameters that are specifies inside the YAML header. But here this doesn’t work because includes don’t copy the YAML header from the included file.
Step 4: Define params
in the Master File
To solve this, define the params
object manually in a code chunk before each include. For example, your report could look like this:

That way, the copied-and-pasted code from species_report.qmd
will work because it is preceded by a code chunk that defines params
.
Step 5: Repeat for Multiple Datasets
Now, you can repeat the same process to include multiple sections, each with a different dataset:

This reuses the same species report over and over, but with different params
each time. Super efficient, isn’t it?
This approach allows you to
reuse the same report structure,
render multiple sections with different data, and
produce a single, polished document
It’s a powerful pattern when working with multiple datasets that need similar analysis! Pretty neat, right? 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