Created
June 3, 2019 14:48
-
-
Save grimbough/efafda8cad546c1a0443f463324a7824 to your computer and use it in GitHub Desktop.
Reusing code chunks from an existing Rmarkdown document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This code chunk will extract all code blocks from `example.Rmd` and write them to a temporary file, preservining chunk options. It will then read them and make those chunks avaliable in the current R environment when the presentation is knitted. | |
```{r include, eval=TRUE, echo=FALSE, include = FALSE} | |
tmp_script <- tempfile() | |
knitr::purl("example.Rmd", output=tmp_script, quiet = TRUE) | |
knitr::read_chunk(tmp_script) | |
``` | |
We can then include a chunk from `example.Rmd` like so: | |
```{r chunk-in-report, eval=TRUE, echo=FALSE} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment