【问题标题】:run just code from one Rmarkdown document in another Rmarkdown document with duplicate chunk names仅在另一个具有重复块名称的 Rmarkdown 文档中运行一个 Rmarkdown 文档中的代码
【发布时间】:2017-03-06 17:04:13
【问题描述】:

我正在用 Rmarkdown 编写一系列相互补充的报告。我想将上一份报告的结果包含在我目前正在处理的报告中。我看到其他建议使用purl 从 Rmarkdown 文档中提取 R 代码然后运行它的问题,所以我尝试了以下操作:

```{r read.previous, echo=FALSE}
source(knitr::purl("previous.Rmd",output=tempfile(),documentation=0))
```

但是当我尝试编织当前报告时,它失败了,抱怨有重复的块名称。我认为documentation=0 参数会删除所有块名称,但似乎在另一个knit 会话中运行purl 会让事情变得混乱。在我的情况下,使所有报告中的块名称唯一是不切实际的。

有没有一种简单的方法可以从 Rmarkdown 文件中获取代码并在另一个文件中执行,而忽略块名称?

【问题讨论】:

    标签: r knitr r-markdown


    【解决方案1】:

    如下添加一段代码应该可以解决你的问题:

    ```{r}
    options(knitr.duplicate.label = 'allow')
    ```
    

    【讨论】:

      猜你喜欢
      • 2014-09-05
      • 1970-01-01
      • 2016-03-12
      • 1970-01-01
      • 2013-07-28
      • 1970-01-01
      • 1970-01-01
      • 2018-11-05
      • 1970-01-01
      相关资源
      最近更新 更多