When I purl/tangle a document to extract the R chunks into a script, is there any way to:
- exclude an arbitrary chunk (by name say)?
- if not, exclude a chunk if
eval=F(or perhaps I can define a chunk hook/optioninclude=F)?
For example, suppose I have the following Rmd:
```{r setup, echo=F}
library(MASS)
```
First, we perform the setup (assume for some reason I need to evaluate `setup`
silently before I wish to display the chunk to the user, hence the repetition)
```{r setup, eval=F}
```
Here's the function I've been explaining:
```{r function}
plus <- function (a, b) a + b
```
And here's an example of its use:
```{r example}
plus(1, 2)
```
The tangled script looks like this:
## @knitr setup, echo=F
library(MASS)
## @knitr setup, eval=F
library(MASS)
## @knitr function
plus <- function (a, b) a + b
## @knitr example
plus(1, 2)
I have the idea that since I didn't want particular chunks to be evaluated, they at the very least should not appear in the output (in the example above, the second setup chunk).
Additionally it would be nice for me to mark some chunks as "invisible" with respect to the tangled output. I don't want the example chunk in my output script (it was nice in the Rmd for purposes of documentation, but I want to be able to tangle the Rmd and then just source('myfile.r') if I wish to use the plus function, without having to worry about these extra examples executing. Currently I tangle the Rmd and then manually edit out the chunks I don't want out of the script, which seems against the principle of just writing the one Rmd which will provide both documentation and script without extra effort.)
include=Fwill remove it from thepurl'd output, but also from the Rmd (in the version of knitr from github that is; feature doesn't seem present on my computer's version 1.2), so this is not ideal for myexampleblock (where I want it included in the Rmd and removed from the purl'd output) - mathematical.coffeepurl(), which is less frequently used, hence less well developed - Yihui Xiepurl. It extracts all of the chunks, and I'm interested in extracting just some of them (or even extracting particular chunks to particular output files). - mathematical.coffee