Skip to content
R for the Rest of Us Logo

Going Deeper with R

Parameterized Reporting, Part 1

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:

  1. Make sure you have the usethis package installed (if you don’t, run install.packages("usethis") in the console).

  2. 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:

  1. Open the file called report.qmd and render it to see what it looks like.

  2. Add a parameter in your YAML for continent and set its value to Asia.

  3. On line 19, change the code to filter the gapminder data using the continent parameter.

  4. On line 23, use inline R code to replace Asia with your continent parameter.

  5. Make sure you can render your report and have everything work exactly the same as when you first rendered.

Have any questions? Put them below and we will help you out!

You need to be signed-in to comment on this post. Login.

Course Content

44 Lessons