Skip to content
Back to formatted view

Raw Message

Message-ID: <4DAADD6D.1030403@gmail.com>
Date: 2011-04-17T12:30:37Z
From: Duncan Murdoch
Subject: sweave options with variable
In-Reply-To: <BANLkTimrqec=9JjGW6cJsHt+HBti+x2kaw@mail.gmail.com>

On 11-04-17 2:41 AM, Kai Ying wrote:
> hello:
>     Do any one know how to set sweave option by variable, for example I want
> set some of my selected code chunk with:
> <<eval=needRun>>= rather than<<eval=TRUE>>=, so  I can change the action
> only in the head by change the variable "needRun" one times.
> I have tried use "\Def" and "\newcommand", both do not work, so I suppose it
> is related with R/Sweave its self.
> thanks for any good suggestion.
>

You can't do that, but you can get a similar effect this way:

<<echo=FALSE>>=
needRun <- TRUE
@

...

<<thecode,eval=FALSE>>=
someSlowFunction()
@

<<echo=FALSE>>=
if (needRun) {
<<thecode>>
}
@

Or you could use cacheSweave or weaver for caching, which may do what 
you want, or write your own Sweave driver to do exactly what you want.

Duncan Murdoch