Skip to content
R in 3 Months Starts March 13. Learn More →
R for the Rest of Us Logo

Going Deeper with R

Parameterized Reporting, Part 3

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
library(quarto)
library(tidyverse)
library(gapminder)

countries <-
  gapminder |>
  distinct(country) |>
  pull(country) |>
  as.character()

reports <-
  tibble(
    input = "example-report.qmd",
    output_file = str_glue("{countries}.html"),
    execute_params = map(countries, ~ list(country = .))
  )

pwalk(reports, quarto_render)

Your Turn

  1. Open the file called render-part-2.R.

  2. Replace all instances of TODO with the correct text.

  3. Render your reports.

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

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

Amalie Baisgaard

Amalie Baisgaard • June 4, 2024

I dont think I get the right results. Despite using the code from the "Solution" folder, I get all the different HTML files but the all only show data for New Zealand and Australia. The names are correct for the different continents and filenames, bit the data in the graph is only New Zealand and Australia.

What have I done wrong?

Here is the code:

library(quarto)
library(tidyverse)
library(gapminder)

continents <-
  gapminder |>
  distinct(continent) |>
  pull(continent) |>
  as.character()

reports <-
  tibble(
    input = "report.qmd",
    output_file = str_glue("{continents}.html"),
    execute_params = map(continents, ~list(continent = .))
  )

pwalk(reports, quarto_render)
David Keyes

David Keyes Founder • June 4, 2024

I actually think this was an error on my part. Please go in and change the YAML to this:

---
title: "Population Report"
format: 
  html:
    embed-resources: true
execute: 
  echo: false
  warning: false
  message: false
---

The line that says embed-resources: true should fix this for you!

Amalie Baisgaard

Amalie Baisgaard • June 5, 2024

Hi David

Should the YAML you send go to the "report.qmd" or the "render-part-2.R" file?

David Keyes

David Keyes Founder • June 5, 2024

In the report.qmd file.

Course Content

44 Lessons