yihui/knitr — Issue #108: selectively include output of a chunk?
Author: baptiste
Created: 2012-01-25 08:05:00+00:00
State: open

Hi,

I've been using the very handy externalization feature of `knitr`, where I can conveniently develop the R code, and when it's polished insert the relevant bits inside a Rnw document. A common problem I face is the following: say my analysis is split into a few steps,

1- (lengthy / messy) definition of some functions

2- call to the function

3- (messy / lengthy) creation of the plot using ggplot2

4- printing the plot

In the final report, I often find I don't want to overwhelm the reader (me, in fact) with technical details such as (1) and (3). In the current workflow, this means that I'll have to split this into 4 chunks, even though it's the same of the study. Further, I need to worry about setting echo=T/F, include=T/F, dependson= for each of these 4 chunks.

I wonder if this could be simplified somehow, by allowing one of two things:

- have the option show no _text_ output, but still print _plots_ (meaning I can keep steps 3 and 4 in the same chunk)

- provide an internal keyword in the form of R comments that defines lines that may be exluded from the echoed code. Something along those lines:

```r
##@knitr messychunk

##@hide
foo = function(...){

## ...

}

##@show
result <- lapply(1:10, foo)
summary(result)

plot(result)

##@hide
p <- ggplot(result) +
## ....

##@show
p
```