你能 call/render 一个参数化的 rmd 报告在另一个参数化的 rmd 报告中吗 - rmarkdown
Can you call/render a parameterized rmd report within another parameterized rmd report - rmarkdown
我想知道是否真的可以从另一个参数化报告中 call/render 一个参数化报告?
我找到了 [this][1],但似乎没有找到解决方案。
下面是一个最小的例子,其中 main-report.rmd 尝试 call/render sub-report-1.rmd。两个报告在 YAML header.
中具有相同的参数
图书馆(此处)
sub-report-1.rmd
---
title: "Secondary report to run"
output: html_document
params:
country: "Canada"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
paste0("Hello ", params$country)
```
main-report.rmd
---
title: "Main report"
output: html_document
params:
country: "France"
---
```{r run1, include=FALSE}
rmarkdown::render(here::here("rmd", "sub-report-1.rmd"),
output_format = "html_document",
output_file="report1.html",
params = list(country=params$country))
```
我收到以下错误:
Error: params object already exists in the knit environment so can't
be overwritten by rend param. Execution halted.
解决方案是在渲染函数中使用另一个参数:envir = new.env()
。问题是对象 params
已被使用。
rmarkdown::render(here::here("rmd", "sub-report-1.rmd"),
output_format = "html_document",
output_file="report1.html",
params = list(country=params$country),
envir = new.env())
我想知道是否真的可以从另一个参数化报告中 call/render 一个参数化报告?
我找到了 [this][1],但似乎没有找到解决方案。
下面是一个最小的例子,其中 main-report.rmd 尝试 call/render sub-report-1.rmd。两个报告在 YAML header.
中具有相同的参数图书馆(此处)
sub-report-1.rmd
---
title: "Secondary report to run"
output: html_document
params:
country: "Canada"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
paste0("Hello ", params$country)
```
main-report.rmd
---
title: "Main report"
output: html_document
params:
country: "France"
---
```{r run1, include=FALSE}
rmarkdown::render(here::here("rmd", "sub-report-1.rmd"),
output_format = "html_document",
output_file="report1.html",
params = list(country=params$country))
```
我收到以下错误:
Error: params object already exists in the knit environment so can't be overwritten by rend param. Execution halted.
解决方案是在渲染函数中使用另一个参数:envir = new.env()
。问题是对象 params
已被使用。
rmarkdown::render(here::here("rmd", "sub-report-1.rmd"),
output_format = "html_document",
output_file="report1.html",
params = list(country=params$country),
envir = new.env())