3

I need to generate a thousand R Markdown files, each essentially the same, just with different titles and a different subset of the data. Is there a way to store those titles and subsets in objects and automate creating and knitting the R Markdown files?

Jacob Curtis
  • 788
  • 1
  • 8
  • 22
  • Yes. You want to search for "Parameterized Reports." You may write a script to loop through your conditions and pass the parameters to the template with the correct data and titles. For example, https://stackoverflow.com/questions/32479130/passing-parameters-to-r-markdown – Benjamin Mar 27 '18 at 13:01
  • Here's another similar question with a great answer. https://stackoverflow.com/questions/38572219/how-to-create-a-different-report-for-each-subset-of-a-data-frame-with-r-markdown – Benjamin Mar 27 '18 at 13:06

1 Answers1

4

Yes. When you klick the knit button in Rstudio, it calls the function rmarkdown::render(). This can also be done in code, either in a for loop, with apply or the purrr-version of apply called map. You will need to create a rmarkdown-document that takes parameters for the title and the subset first and then pass these to the render-function in said way.

For an introduction to paramters in your documents have a look at the documentation here.

Jannik Buhr
  • 1,788
  • 2
  • 11
  • 11