I would like to create Word files within a loop (one Word file for each school).
Knitr seems not to have a knit2word
function (but knit2html
, knit2pdf
etc.). Can this still be done?
schools <- c("A", "B", "C")
for(school in schools){
knitr::knit("analysis.Rmd", output=paste0("stats_school ", school, ".R"))
}
The Rmd file starts like this:
---
title: "The title"
author: "My Name"
output: word_document
---
CodePudding user response:
To render your Rmd in a loop (whether to word or html or ... ) you could use rmarkdown::render
:
schools <- c("A", "B", "C")
for(school in schools){
rmarkdown::render("analysis.Rmd", output_file=paste0("stats_school ", school))
}