问题
I am trying to generate about 50 reports with the same template in rMarkdown. I do not want to change the name of the input file every time and I would like to choose different names for output files.
Is there any way how to automate this process?
Thank you.
回答1:
Another option is to render your reports using the render() function of the rmarkdown package in a seperate R script.
report.Rmd looks like this:
---
output: pdf_document
---
# A table with data received from R script
```{r,results='asis'}
library("knitr")
kable(mydataset)
```
The R script looks like that:
library("rmarkdown")
for (i in 1:50){
mydataset <- head(mtcars)
render( input="report.Rmd", output_file=paste0("reportNo_", i, ".pdf") )
}
来源:https://stackoverflow.com/questions/28368150/automatically-generated-reports-using-rmarkdown