[Rd] Re: [R] calling sweave function from latex

Friedrich.Leisch@univie.ac.at Friedrich.Leisch@univie.ac.at
Thu Jan 30 12:30:04 2003

[ Moved to r-devel ]

>>>>> On Wed, 29 Jan 2003 12:17:29 -0500,
>>>>> Frank E Harrell (FEH) wrote:

  > Before I discovered Sweave, I used methods that are detailed in Chapter 13 of http://hesweb1.med.virginia.edu/biostat/s/doc/splus.pdf for managing large analysis projects.  The do function in the Hmisc library (not yet tested for R) was created to manage code chunks that each create their own series of output listings and postscript graphics files.  For conditional execution of chunks, it helps me to set flags at the start of the document so that I don't have to hunt for any flags or if statements.  I do things like

  > importdata    <- FALSE
  > fitmodel      <- FALSE
  > validatemodel <- TRUE

  > if(importdata) {
  >  ...
  > }
  > if(fitmodel) {
  >  ...
  > }
  > if(validatemodel) {
  >  ... time-consuming bootstrap code ...
  > }

  > or use

  > do(importdata, { ... code chunk ...})
  > do(fitmodel, {... code chunk ...})
  > do(validatemodel, {... code chunk ...})

  > where the keys such as 'importdata' are used as root names of files created by that code chunk.  The 'validatemodel' chunk creates by default 'validatemodel.lst' to contain the printed output, and files such as 'validatemodel.ps' for graphics.

  > It would be nice if Sweave could implement this type of model.  In LaTeX I find it invaluable to set flags for conditional text insertion using \def and \ifnum \fi.  For a report, the text might always be included but S chunks only condionally run, with previous output used when a chunk is bypassed.

  > Please take a look at Chapter 13 of the above referenced document if you have time, to see if it gives you any ideas worth pursuing.

Thanks a lot, I'll add it to my pile of weekend reading material.

The code you give above looks similar to what I have in mind. Each
chunk can list previous chunks that it depends on (by default all
previous chunks). Sweave will only re-run the chunk if (the parsed
version of) the code has changed, and otherwise re-use the existing
material. Additionally I want to have a hook that allows turning off
evaluation based on chunk names.

I already have an S4 representation of parsed Sweave files, currently
I am working on a representation of the evaluated object (and
functions to get it).


                        Friedrich Leisch 
Institut für Statistik & DSS                Tel: (+43 1) 4277 38613
Universität Wien  		            Fax: (+43 1) 4277 38639
Universitätsstraße 5                  Friedrich.Leisch@univie.ac.at
A-1010 Wien, Austria             http://www.ci.tuwien.ac.at/~leisch