KamloopsR / Meetup

This repository is meant to provide a place to discuss, share, and plan
8 stars 3 forks source link

add notes on parameterized reports #14

Open stefaniebutland opened 8 months ago

stefaniebutland commented 8 months ago

Purpose Understand how we used parameterized reporting to create Openscapes Champions Certificates, so I can improve and expand their use. Build more R skills.

Outcomes

Process Find a tutorial or two to start with the basics.

Notes

From Render parameterized reports with Quarto, John Paul Helveston, 2023

One of the most common use cases for me is creating parameterized reports. A parameterized report is one that uses a .qmd file with parameters that can be passed to it while rendering, enabling the ability to create different versions of the output report based on the parameters. ... Using parameters like student_name, grade, and feedback, I am able to use a single .qmd file and then render a unique report for each student where those parameters are replaced with the appropriate information for each student.

This is exactly the starter tutorial I needed because the example parallels my use case! He provides this example code to create a report for every student in his class. Uses a for-loop as we do.

df <- readr::[read_csv](https://readr.tidyverse.org/reference/read_delim.html)("grades.csv")

for (i in 1:[nrow](https://rdrr.io/r/base/nrow.html)(df)) {
    student <- df[i, ] # Each row is a unique student
    quarto::[quarto_render](https://rdrr.io/pkg/quarto/man/quarto_render.html)(
        input = "template.qmd",
        output_file = [paste0](https://rdrr.io/r/base/paste.html)("feedback-", student$name, ".pdf"),
        execute_params = [list](https://rdrr.io/r/base/list.html)(
            name = student$name,
            grade = student$grade
        )
    )
}

Watched 30-min video for this. Super helpful Repo: https://github.com/jhelvy/quarto-pdf-demo

stefaniebutland commented 7 months ago

created a repo for working through this: https://github.com/stefaniebutland/param-reports