[R] Sweave and optional document sections

Kyle Covington kylecovington1 at gmail.com
Wed Jan 25 23:01:25 CET 2017

I was just trying to do this and I think I have a reasonable solution that seems to be working well.

In the main document you can include a chunk with a logical section:

<<optnsa, echo=F, results=tex>>=
  {sink("/dev/null"); Sweave(’subsection.Rnw'); sink(); } 

Then you can put your subsection logic into subsection.Rnw, just make sure to remove all of the default latex header stuff, just put in the blocks that you want to process:

This comes from a subsection.

cat(”I’m in a  subsection”)

This worked for me


More information about the R-help mailing list