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

Michael Hoffman b3i4old02 at sneakemail.com
Sun Dec 2 02:45:53 CET 2007


Duncan Murdoch wrote:

> On 01/12/2007 2:38 PM, Michael Hoffman wrote:
>> Dieter Menne wrote:
>>> Michael Hoffman <b3i4old02 <at> sneakemail.com> writes:
>>>
>>>> I would like to be able to do something like this:
>>>>
>>>>    <<echo=F,fig=T,width=mywidth>>=
>>>>    ...
>>>>    @
>>>>
>>>> with mywidth set in a previous code chunk. Is there a way to do this in 
>>>> Sweave?
>>>>
>>> Not in the <<>>, but you could set a hook for fig:
>>>
>>>
>>> >From Sweave docs:
>>>
>>> If option "SweaveHooks" is defined as list(fig = foo), and foo is a function,
>>> then it would be executed before the code in each figure chunk. This is
>>> especially useful to set defaults for the graphical parameters in a series of
>>> figure chunks.
>> Thanks. I guess what I really want to do is switch between one of two 
>> settings. Only one value can be in the defaults, and I would like some 
>> way of setting the other value. This might not be easily possible, but I 
>> thought I would ask.
> 
> My understanding is that Michael wants to have the Sweave options in a 
> chunk depend on a calculation happening in the underlying R session. 

That would be really nice and allow some things I hadn't even imagined 
would be possible.

But really I just would like the ability to set a variable statically 
and reuse it. Using a macro system like m4 would work, although I 
dislike the idea of adding yet another macro system to my poor document.



More information about the R-devel mailing list