Jmac
Jmac

Reputation: 243

Can you call/render a parameterized rmd report within another parameterized rmd report - rmarkdown

I'm wondering if it is actually possible to call/render a parameterized report from within another parameterized report?

I found [this][1] but it doesn't seem to come up with a solution.

Below is a minimal example where main-report.rmd tries to call/render sub-report-1.rmd . Both reports have the same params in the YAML header.

library(here)

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))


```

I get the following error:

Error: params object already exists in the knit environment so can't be overwritten by rend param. Execution halted.

Upvotes: 0

Views: 449

Answers (1)

J_F
J_F

Reputation: 10372

The solution is to use another parameter in the render function: envir = new.env(). The problem is that object params is already used.

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())

Upvotes: 1

Related Questions