Say I have a .Rnw
file containing the usual LaTex mixed in with R code chunks. (I'm especially interested in converting a .Rnw
slides document, but this question applies to any .Rnw
document). Now I want to convert this to a file which contains all of the R code, plus all of the text that would normally be generated by LaTex, as R comments. In other words, the functionality I want is similar to what Stangle()
does, but I also want all the text part of the LaTex converted to plain text that's commented out in the resulting .R file.
This would be a very convenient way to automatically generate a commented R file that's easy to look at in your favorite syntax-highlighting editor (e.g. emacs). This might not sound like a great idea for an Sweave document that's a long article with only a bit of R code, but it starts to look appealing when the .Rnw
document is actually a slide presentation (e.g. using beamer
) -- then the text portion of the slides would make perfect comments for the R code.
Anyone have any ideas on how to do this? Thanks in advance.
"^<<.*>>=?$"
for start chunk. But it's very neat approach, anyway... nice usage ofmapply
. – Lassalle