Bulk document creation in R markdown

I am wondering if anyone can help me with the dilemma I am experiencing.

I have a data set of about 300 people that contains some basic information about them (e.g. age, gender). I want to link a separate R markdown report for each person who details this basic information in Word format. And then I want to save each report with their unique name.

The actual code that is behind the report does not change, but only the details of each person. For instance:

Report 1: "Sally is a 34 year old woman." (Which I would save as Sally.doc)

Report 2: "Mike is a 21 year old man." (Saved as Mike.doc)

Etc etc.

Is there a way to do this without manually filtering the data, re-pulling the document, and manually saving with unique names?

Thanks a lot!

+5
source share
1 answer

Use the render function and pass a list of function names:

renderMyDocument <- function(name) { rmarkdown::render("./printing_procedures/dagr_parent.Rmd", params = list(names = name), output_file = paste("~/document_", name, '.doc', sep = '') ) } lapply(names, renderMyDocument) 

Then just make sure your RMD file can accept params via YAML:

 --- params: names: --- 

RStudio documentation for parameterized reports here: https://rmarkdown.rstudio.com/developer_parameterized_reports.html

+3
source

Source: https://habr.com/ru/post/1275905/


All Articles