run just code from one Rmarkdown document in another Rmarkdown document with duplicate chunk names

核能气质少年 提交于 2019-12-14 01:18:29

问题


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

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.

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


回答1:


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

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


来源:https://stackoverflow.com/questions/42631398/run-just-code-from-one-rmarkdown-document-in-another-rmarkdown-document-with-dup

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!