Parameterized reports in Quarto
After watching this video on YouTube, I did what all men do, make some slight modifications and claim it is a new thing I just came up with and take the applause. The points are explained very well in the video but let me summarise it given you are a busy person:
I want to generate a different report for each value in my data
Here is my cheap knockoff
purrr::map( ## Looping
gapminder::gapminder |> ## gapminder package
distinct(continent) |> pull(), ## Explained in the video
(x) quarto::quarto_render( ## You must install quarto
input = "gapminder.qmd", ## Source file
output_format = "pdf", ## Other options exists
execute_params = list(continent = x), ## Sets the continent parameter
output_file = paste(x, ".pdf", sep = "") ## Cheap knockoff, the str_glue is better
)
)
Click here to download the .qmd
file which will be executed when the code above is run. The .qmd
will not run independently unless you set a default value for the continent, it is on purpose
Responses