使用 rMarkdown 自动生成报告 [英] Automatically generated reports using rMarkdown
本文介绍了使用 rMarkdown 自动生成报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 rMarkdown 中使用相同的模板生成大约 50 个报告.我不想每次都更改输入文件的名称,我想为输出文件选择不同的名称.
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?
谢谢.
推荐答案
另一种选择是在单独的 R 脚本中使用 rmarkdown 包的 render() 函数呈现您的报告.
Another option is to render your reports using the render() function of the rmarkdown package in a seperate R script.
report.Rmd 看起来像这样:
report.Rmd looks like this:
---
output: pdf_document
---
# A table with data received from R script
```{r,results='asis'}
library("knitr")
kable(mydataset)
```
R 脚本如下所示:
library("rmarkdown")
for (i in 1:50){
mydataset <- head(mtcars)
render( input="report.Rmd", output_file=paste0("reportNo_", i, ".pdf") )
}
这篇关于使用 rMarkdown 自动生成报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文