Re: [R] sweave options with variable

From: Duncan Murdoch <>
Date: Sun, 17 Apr 2011 08:30:37 -0400

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:

needRun <- TRUE



if (needRun) {

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 mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Sun 17 Apr 2011 - 12:33:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 17 Apr 2011 - 15:40:31 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive