Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically generated reports using rMarkdown

Tags:

r

r-markdown

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.

like image 690
kojak Avatar asked Feb 12 '23 00:02

kojak


1 Answers

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") )
} 
like image 187
jmjr Avatar answered Feb 23 '23 16:02

jmjr