[Rd] [R] Sweave: Variables in code chunk headers

Michael Hoffman b3i4old02 at sneakemail.com
Sun Dec 2 20:41:04 CET 2007


Duncan Murdoch wrote:

> I put together a clunky way to handle that for a presentation last week; 
> it may be enough for you.
> 
> I leave the Sweave options at their defaults, but I have code chunks 
> that affect the appearance, and I run those without echoing to switch 
> between a couple of formats.  For example, I have some pages that 
> display one figure, and others that display two.

That is a decent way of doing what I am suggesting. Probably too 
complicated to be worth it if I am just changing one variable.

> One other thing that would have helped with this approach would be a way 
> to include another file:  then I wouldn't have to repeat those 
> definitions in every Rnw of the project.

Yet another candidate for (yet another) pre-processing step. :)

Of course, you could load the complicated bits in another file with 
source(). You'd still have to redefine <<single>> and <<double>> 
everywhere, but at least you would be able to change the option settings 
easily. Like this:

<<echo=F>>
source("init.R")
@

<<single, echo=F, eval=F>>=
setup.single() # loaded from init.R
@



More information about the R-devel mailing list