r - Conditional `echo` (or eval or include) in rmarkdown chunks -
i create rmarkdown document (pdf or html) has chunks "executed" conditionally. particular case have in mind might want more verbose , documented version of output internal review colleagues, , shorter version external consumers. may not want or need show data manipulation steps client, key graphs , tables. not want make 2 separate documents or have manually indicate show or not.
is there way set switch @ beginning of rmd indicates, e.g., verbose=t run chunks or verbose=f toggles echo=f (or include=f)?
thank you.
knitr options can stated r expressions. per the "output" documentation on knitr webpage:
note options in knitr can take values r expressions, brings feature of conditional evaluation introduced in main manual. in short,
eval=dothis
means real value of eval taken variable nameddothis
in global environment; manipulating variable, can turn on/off evaluation of batch of chunks.
in other words if write chunks like:
```{r label} donextchunk <- as.logical(rbinom(1,1,.5)) ``` ```{r conditional, eval = donextchunk} "hello world!" ```
Comments
Post a Comment