问题
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