Parameterized Reporting
with Quarto

Jadey Ryan // February 21, 2024
R-Ladies Abuja

Acknowledgements

R-Ladies Abuja Logo


Website and slides were created using the workshop template from Jadey Ryan.

Disclaimer and license

Opinions expressed are solely my own and do not express the views of my employer or any organizations I am associated with.


This work is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA).

Jadey Ryan

Data scientist at WA Dept of Agriculture

The Coding Cats: cat & code themed merch

jadeyryan.com

@jadeynryan

linkedin.com/in/jadey-ryan

jadeynryan

thecodingcats.etsy.com

Three snowshoe siamese cats in loaf mode. From left to right: Tai, Mai, and Skye

Jadey collecting a bulk density soil sample in a field of wheat stubble.

Logistics

Login to Posit Cloud workspace: bit.ly/rladies-parameterized-quarto.

If Posit Cloud doesn’t work, download materials locally:

usethis::use_course(
  "https://github.com/jadeynryan/parameterized-quarto-workshop/raw/main/exercises/exercises.zip"
#  ,destdir = "___"
  )

Ask questions in the public Zoom chat or raise hand ✋.

Workshop structure: presentation, demos/exercises, questions to answer in 💬 Chat.

💪🏼 Exercise 0


💬 Chat: share your name, where you’re calling from, and one thing you’ve made that you’re proud of.

01:00

Learning objectives

  1. Understand what parameterized reporting is and when it is useful.


  1. Learn how to convert a report into a parameterized template.


  1. Render all variations of the report at once using {quarto} and {purrr}.


  1. Generate multiple format outputs from the same template file with conditional content and conditional code execution.

Syntax and RStudio aside

Pipes

  • 2014+ magrittr pipe %>%

  • 2021+ (R \(\geq\) 4.1.0) native R pipe |>

Isabella Velásquez’s blog post Understanding the native R pipe |> (2022)


do_something(arg1, arg2, arg3, ...)

arg1 |>  
  do_something(arg2, arg3)
mean(0:10)

0:10 |> 
  mean()


To change shortcut to the native pipe:

ToolsGlobal OptionsCodeEditingUse Native Pipe Operator

Windows: Ctrl + Shift + M

Mac: Cmd + Shift + M

Namespacing

package::function()

dplyr::select()

  • tells R explicitly to use the function select from the package dplyr

  • helps avoid name conflicts (e.g., MASS::select())

  • does not require library(dplyr)

library(dplyr)

mtcars |>  
  select(mpg, cyl) 
# library(dplyr) not needed

mtcars |>  
  dplyr::select(mpg, cyl) 

RStudio options

ToolsGlobal Options

  • Fussy YAML indentation:

    CodeDisplayIndentation guides:Rainbow lines


  • Match parentheses:

    CodeDisplayIndentation guides: → Check Use rainbow parentheses


  • Matching divs:

    R MarkdownAdvanced → Check Use rainbow fenced divs