07:00
RStudio/Quarto integration:
Render button in RStudio or Cmd/Ctrl + Shift + K keyboard shortcut
โจ Quarto R package โจ
Quarto CLI
Change parameters in the YAML and render using
Render button.
Look at the unique pet breeds and pick your favorite.
In 2-quarto-render.qmd, change the default parameters in the YAML to your favorite pet type and breed. Render using the
Render button.
๐ฌ Chat: Which breed did you pick and why? What do you think will happen if you set the pet_type default parameter to โcatsโ and the fave_breed parameter to โAmerican Bulldogโ?
Try it out and discuss what happend!
07:00
Change parameters and render using quarto_render().
Render with quarto::quarto_render().
๐ฌ Chat: What kinds of variables will you use as parameters for your reports?
07:00
One HTML report for each cat breed and each dog breed.
Change the default params in the YAML.
Render button or Cmd/Ctrl + Shift + K keyboard shortcut.
Rename the rendered report to include the parameter & prevent overwriting.
Repeat 537 times.
๐ญ
quarto::quarto_render(
input = here::here("2-quarto-render.qmd"),
output_file = "dogs-affenpinscher-report.html",
execute_params = list(
pet_type = "dogs",
fave_breed = "Affenpinscher"))
quarto::quarto_render(
input = here::here("2-quarto-render.qmd"),
output_file = "dogs-afghan-hound-report.html",
execute_params = list(
pet_type = "dogs",
fave_breed = "Afghan Hound"))
quarto::quarto_render(
input = here::here("2-quarto-render.qmd"),
output_file = "dogs-aidi-chien-de-montagne-de-l-atlas-report.html",
execute_params = list(
pet_type = "dogs",
fave_breed = "Aidi Chien De Montagne De L Atlas"))
quarto::quarto_render(
input = here::here("2-quarto-render.qmd"),
output_file = "dogs-akita-report.html",
execute_params = list(
pet_type = "dogs",
fave_breed = "Akita"))
# + 534 more times...
# ๐ญCreate a dataframe with three columns that match quarto_render() args:
output_format: file type (html, revealjs, pdf, docx, etc.)
output_file: file name with extension
execute_params: named list of parameters
Map over each row:
purrr::pwalk(dataframe, quarto_render, <arguments for quarto_render>) ๐purrr functions for iterationMap functions apply the same action/function to each element of an object.
Base R apply() functions are map functions.
purrr map functions have consistent syntax and the output data type is predictable.
for loops โ lapply() โ purrr::map()

Learn more:
R-Ladies Baltimore presentation Make your R Code purr with purrr
pet_reports <- pets |>
dplyr::distinct(pet_type, breed) |> # Get distinct pet/breed combos
dplyr::mutate(
output_format = "html", # Make output_format column
output_file = paste( # Make output_file column:
tolower(pet_type), # cats-abyssiniane-report.html
tolower(gsub(" ", "-", breed)),
"report.html",
sep = "-"
),
execute_params = purrr::map2( # Make execute_params column
pet_type,
breed,
\(pet_type, breed) list(pet_type = pet_type, breed = breed)))pet_reports_subset <- pet_reports |>
dplyr::slice_head(n = 2, by = pet_type) |>
dplyr::select(output_file, execute_params)
pet_reports_subset| output_file | execute_params |
|---|---|
| cats-abyssiniane-report.html | cats , Abyssiniane |
| cats-aegean-cat-report.html | cats , Aegean Cat |
| dogs-affenpinscher-report.html | dogs , Affenpinscher |
| dogs-afghan-hound-report.html | dogs , Afghan Hound |
purrr::pwalk() iterates over multiple arguments simultaneously.
First .l argument is a list of vectors.
.l that iterates over rows.Note
input is the only named argument of quarto_render() included in pwalk().
output_format, output_file, and execute_params are already passed in through the dataframe.
Add to the format: YAML option to render additional output formats from the same .qmd file.
Links to download the other formats will automatically appear in HTML documents.
Choose which format links to include:
Programmatically render all reports in all formats in 3-purrr-render-demo.qmd and 3-purrr-render-demo.R.
๐ก Use these files as a template and modify them for your own projects!
Canโt render reports to another directory.
output-dir YAML option only works for Quarto projects that contain a _quarto.yml config file.
Workaround: use {fs} to move files after rendering.
See 3-purrr-render-demo.R for example.
More info: GitHub discussion and GitHub issue.
Canโt embed resources for a Quarto document in a subfolder.
If using embed-resources: true YAML option, .qmd canโt be in subfolder, otherwise:
[WARNING] Could not fetch resource โฆ
More info: GitHub discussion and GitHub issue.
30:00