[R] Sweave : change value in rnw file to generate multiple "single"reports ?

Gabor Grothendieck ggrothendieck at gmail.com
Mon Dec 10 19:46:44 CET 2007

On Dec 10, 2007 1:32 PM, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
> On 12/10/2007 11:49 AM, ONKELINX, Thierry wrote:
> > I think something like this would work.
> >
> > Change your query to
> >
> > rs <- dbSendQuery(con, statement = paste("select * from treatdata where
> > name='", whichDevice,"'", sep = ""))
> >
> > And then create a script like.
> >
> > whichDevice <- "Device1"
> > Sweave("myfile.rnw")
> > whichDevice <- "Device2"
> > Sweave("myfile.rnw")
> Yes, I had forgotten that works.  I usually use R CMD Sweave, where (as
> Gabor mentioned) it's harder to set variables.

Note that while the Thierry's idea is quite good it since it avoids the use
of shell or batch files it still does have the disadvantage of requiring an
extra file in the case where the report is being spawned from some other
system such as a web application written in php as it requires both a
.R file and a .Rnw file.

On the other hand if R CMD Sweave accepted arguments one could do it all
in the Sweave file and avoid the extra complexity of an intermediate .R or
shell/batch file in the first place.

More information about the R-help mailing list