The two strategies are Stangle
(for a Sweave variant) and purl
for a knitr variant. My impression for .Rnw files is that they are more or less equivalent, but purl
should work for other types of files, as well.
Some simple examples:
f <- 'somefile.Rnw'
knitr::purl(f)
Stangle(f)
Either way you can then run the created code file using source
.
Note: This post describes an chunk option for knitr to selectively purl
chunks, which may be helpful, too.