从循环传递参数以在Rmarkdown中生成动态报告

问题描述 投票:0回答:1

Rmarkdown的新手,我想创建动态报告,其中每个报告部分都是从模板(子)文档生成的。然后,每个部分将从呈现的pdf中的新页面开始。

我的方法当前基于此post,该示例显示了如何在子级中动态生成文本(有效),但是我无法将循环的内容传输到R代码块中,可能是因为[C0 ]的定义方式不正确。

这是我的父文档的样子:

params

这就是孩子的样子

---
title: "Dynamic RMarkdown"
output: pdf_document
---


```{r setup, include=FALSE}
library("knitr")
options(knitr.duplicate.label = "allow")
```

# Automate Chunks of Analysis in R Markdown 
Blahblah Blabla
\newpage

```{r run-numeric-md, include=FALSE}
out = NULL
for (i in as.character(unique(iris$Species))) {
  out = c(out, knit_expand('template.Rmd'))
  params <- list(species = i)
}
```

`r paste(knit(text = out), collapse = '\n')`

据我所知,实际传递的参数是循环中生成的数据集中的最后一个--- title: "template" output: html_document params: species: NA --- # This is the reporting section of Species {{i}} This is a plot of Sepal length and width based on species {{i}}. ```{r plot2} paste(params$species) # plot doesnt work work # plot(iris$Sepal.Length[iris$Species=={{i}}], # iris$Sepal.Width[iris$Species=={{i}}] # ) ``` \newpage ,但我不确定为什么该图无法使用。有人可以帮我解决此问题吗?

r r-markdown pdflatex
1个回答
0
投票

好无需通过species。以下作品也]]

父母:

params

儿童

---
title: "Dynamic RMarkdown"
output: pdf_document
---


```{r setup, include=FALSE}
library("knitr")
options(knitr.duplicate.label = "allow")
```

# Automate Chunks of Analysis in R Markdown 
Blahblah Blahblah Main text before individual sections
\newpage

```{r run-numeric-md, include=FALSE}
out = NULL
for (i in as.character(unique(iris$Species))) {
  out = c(out, knit_expand('template.Rmd'))
}
```

`r paste(knit(text = out), collapse = '\n')`
    
© www.soinside.com 2019 - 2024. All rights reserved.