从另一个Rmarkdown文档中的一个Rmarkdown文档仅运行代码,该代码具有重复的块名称 [英] run just code from one Rmarkdown document in another Rmarkdown document with duplicate chunk names

查看:240
本文介绍了从另一个Rmarkdown文档中的一个Rmarkdown文档仅运行代码,该代码具有重复的块名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am writing a series of reports in Rmarkdown that build off each other. I would like to include the results from the previous report in the report I am currently working on. I have seen other questions that suggested using purl to extract R code from a Rmarkdown document and then run that, so I tried the following:

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

但是当我尝试编织当前报告时,它失败,并抱怨有重复的块名称.我以为documentation=0参数会删除所有块名称,但是看来在另一个knit会话中运行purl会使事情变得混乱.在我的案例中,使所有块名称在报告中唯一是不现实的.

But when I try to knit the current report, it fails, complaining that there are duplicate chunk names. I thought the documentation=0 argument would remove all chunk names, but it appears that running purl inside another knit session is getting things all confused. Making all the chunk names unique across reports is impractical in my case.

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

Is there a simple way to just get the code from an Rmarkdown file and execute inside another, ignoring chunk names?

推荐答案

按如下所示添加代码段可以解决您的问题:

Adding a chunk of code as follows should resolve your problem:

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

这篇关于从另一个Rmarkdown文档中的一个Rmarkdown文档仅运行代码,该代码具有重复的块名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆