Bulk save PDF correspond to dataset's row dynamically

I have student evaluation dataset as df. I've designed the PDF report in rmarkdown format for each student. I want to save the PDF file of each student report.

Data and RMarkdown (index.Rmd)

title: "Evaluation Report of `r params$Student`"
output: pdf_document
  Student: "Student name"
```{r include = FALSE}
# libraries
# data
df <- tribble(
"Michael Scott","80","88","65","Keep working",
"Leslie Knope","76","88","76","Good",
"Jake Peralta","45","87","46","Learn more",
```#(ignore this comment, just for the sake of code visual)
Dear `r df$Student`,

Here is your test score

> `r df$Math`

> `r df$Physics`

> `r df$Computer`

`r df$Note`

Your teacher

I want to save the PDF for each Student with one time run, will save all 3 PDFs. The real case is that I have dataset contains of around 500 people, so save it manually will really time consuming

What I did so far
I'm using for loop but keep didn't work

for (i in 1:3) {
   input =  "index.Rmd",
    params = list(Student = df$Student)
    output_file = paste("Report of", params, ".pdf")

How to best do it?

What didn't work exactly ?

For this kind of thing, I would run rmarkdown::render() in background session - this could allow you to parallelize the rendering. You need to pay attention to resource access thought, and intermediary file naming. This is known limitation: [FR] `*.knit.md` should have a unique name to allow parallelization · Issue #2454 · rstudio/rmarkdown · GitHub
You could copy all project into temp folder, and move back the output to avoid this.

Maybe a tool like The {targets} R package user manual could help for this long running computation.

It depends if what is time consuming is the LaTeX compilation to PDF, or the computation in your document. For the latter, you could use caching mechanism and pre-computing results so that your Rmd only read content from a data base, and do not calculate everythign always; targets should help too with that.

Is there any specific challenge apart from time consuming rendering ?

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.