Using knitr to create HTML slide with separate output of just the R code

Viewed 182

I am using knitr to create a set of lecture slides for a class using R. I would like to create a separate "companion file" that contains just has the R code (corresponding to the slides), so that students can execute the R code by cutting and pasting from the companion file.

For example, in the .Rmd file:

``` {r ....}
plot(x,y)
```

Then there would be a text file with:

plot(x,y)

But, have such a file be automatically produced from the .Rmd file?

Even better if the .Rmd file has such tags:

``` {r basic.plot ....}
plot(x,y)
```

Then, text file has:

# basic.plot
plot(x,y)

Can this be accomplished using knitr?

1 Answers
Related