Parameterized Reporting, Part 1
This lesson is called Parameterized Reporting, Part 1, part of the Going Deeper with R course. This lesson is called Parameterized Reporting, Part 1, part of the Going Deeper with R 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.
View code shown in video
---
title: "Life Expectancy Report"
format: html
execute:
echo: false
warning: false
message: false
params:
country: "Afghanistan"
---
```{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:
Make sure you have the
usethis
package installed (if you don’t, runinstall.packages("usethis")
in the console).Run the code below in the console. Say yes to the prompts. This will download and open an RStudio project for you.
usethis::use_course("https://github.com/rfortherestofus/going-deeper-parameterized-reporting/archive/refs/heads/main.zip")
Then, working in the project:
Open the file called
report.qmd
and render it to see what it looks like.Add a parameter in your YAML for
continent
and set its value to Asia.On line 19, change the code to filter the
gapminder
data using thecontinent
parameter.On line 23, use inline R code to replace Asia with your
continent
parameter.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 has done:
Learn more about parameterized reporting:
Parameterized Quarto reports improve understanding of soil health by Jadey Ryan
R for the Rest of Us book, Chapter 7: Using Parameters to Automate Reports (this covers parameterized reporting with RMarkdown, but it is nearly identical)
Learn How Parameterized Reporting Works with Aaron Williams, Livia Mucciolo and Safia Sayed
Have any questions? Put them below and we will help you out!
Course Content
44 Lessons
You need to be signed-in to comment on this post. Login.