【问题标题】:R - Error when knitting an Rmd file which has code to knit another Rmd file (duplicate "setup" chunk name)R - 编织具有编织另一个 Rmd 文件的代码的 Rmd 文件时出错(重复的“设置”块名称)
【发布时间】:2020-12-30 10:00:45
【问题描述】:

我正在尝试从另一个 .Rmd 文件 (file1) 中用 rmarkdown::render() 编织一个 .Rmd 文件 (file2)。

如果我在 file1 中运行从 file1 交互式呈现 file2 的块,则 file2 呈现良好。

如果我编织 file1 我会收到此错误:

Error in parse_block(g[-1], g[1], params.src, markdown_mode) : 
  Duplicate chunk label 'setup', which has been used for the chunk:
...

如何从其他.Rmd 文件中编织.Rmd 文件?

这是file1file2的MWE内容:

文件1

---
title: "File 1"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_knit$set(root.dir = here::here())
```

# Let's knit it

```{r knit-it}
rmarkdown::render("./file2.Rmd", envir = new.env())
```

文件2

---
title: "File 2"
output: github_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_knit$set(root.dir = here::here())
```

# Knit me

```{r random}
rnorm(2)
```

【问题讨论】:

  • knit-me.Rmd 是哪个文件?我以为你的两个文件叫做file1.Rmdfile2.Rmd

标签: r r-markdown knitr


【解决方案1】:

您应该在另一个 R 会话中渲染另一个文件,例如,

xfun::Rscript_call(rmarkdown::render, list("./file2.Rmd"))

【讨论】:

    猜你喜欢
    • 2017-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多