Parameterized Reporting, Part 1
This lesson is called Parameterized Reporting, Part 1, part of the R in 3 Months (Spring 2026) course. This lesson is called Parameterized Reporting, Part 1, part of the R in 3 Months (Spring 2026) course.
Transcript
Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.
Loading transcript...
View code shown in video
---
title: "Life Expectancy Report"
format: html
execute:
echo: false
warning: false
message: false
params:
country: "Afghanistan"
---
```{r}
if (interactive()) {
params <- rmarkdown::yaml_front_matter(
rstudioapi::getSourceEditorContext()$path
)$params
}
```
```{r}
library(tidyverse)
library(gapminder)
```
```{r}
life_expectancy <-
gapminder |>
select(country, year, lifeExp) |>
filter(country == params$country)
```
## Life Expectancy in `r params$country`
```{r}
ggplot(
data = life_expectancy,
aes(
x = year,
y = lifeExp
)
) +
geom_line() +
theme_minimal()
```
Your Turn
I’ve created a starter project to help you. To install it:
Download the course project at https:://rfor.us/gdprmp.
Open the course project in Positron.
Make sure to install the {gapminder}, {rmarkdown}, and {quarto} packages in order to be able to run the code in the project.
Then, working in the project:
Open the file called
your-turn-report.qmdand render it to see what it looks like.Add a parameter in your YAML for
continentand set its value to Asia.On line 19, change the code to filter the
gapminderdata using thecontinentparameter.On line 25, use inline R code to replace Asia with your
continentparameter.
Make sure you can render your report and have everything work exactly the same as when you first rendered.
Learn More
Example reports that R for the Rest of Us / Clarity Data Studio has done:
Learn more about parameterized reporting:
Have any questions? Put them below and we will help you out!
Course Content
144 Lessons
You need to be signed-in to comment on this post. Login.