以R降价批量创建文档

以R降价批量创建文档

本文介绍了以R降价批量创建文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以帮助我解决我遇到的困境.

I'm wondering if anyone can help me with a dilemma I'm having.

我有大约300个人的数据集,其中包含有关他们的一些基本信息(例如年龄,性别).我想为每个单独的R降价报告编制一个详细的Word格式的基本信息.然后,我想用其唯一名称保存每个报告.

I have a dataset of around 300 individuals that contains some basic information about them (e.g. age, gender). I want to knit a separate R markdown report for each individual that details this basic information, in Word format. And then I want to save each report with their unique name.

位于报表后面的实际代码不会更改,只会更改每个人的详细信息.例如:

The actual code which sits behind the report doesn't change, only the details of each individual. For example:

报告1:莎莉是34岁的女性". (我想另存为Sally.doc)

Report 1: "Sally is a female who is 34 years old". (Which I would want to save as Sally.doc)

报告2:迈克是一名21岁的男性." (另存为Mike.doc)

Report 2: "Mike is a male who is 21 years old." (Saved as Mike.doc)

等等,

有没有一种方法,而无需手动过滤数据,重新编织文档,然后使用唯一名称手动保存?

Is there a way I can do this without manually filtering the data, re-kniting the document, and then saving manually with unique names?

非常感谢!

推荐答案

使用render函数并将名称列表传递给该函数:

Use the render function and pass a list of names to the function:

renderMyDocument <- function(name) {
  rmarkdown::render("./printing_procedures/dagr_parent.Rmd",
                    params = list(names = name),

                    output_file = paste("~/document_", name, '.doc', sep = '')
  )
}

lapply(names, renderMyDocument)

然后只需确保您的RMD文件可以通过YAML接受params参数:

Then just make sure your RMD file can take the params argument via the YAML:

---
params:
  names:
---

有关参数化报告的RStudio文档,位于: https://rmarkdown.rstudio.com/developer_parameterized_reports.html

RStudio documentation on parameterized reports here: https://rmarkdown.rstudio.com/developer_parameterized_reports.html

这篇关于以R降价批量创建文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 02:11