[R] calling sweave function from latex

Friedrich.Leisch@ci.tuwien.ac.at Friedrich.Leisch at ci.tuwien.ac.at
Wed Jan 29 11:19:02 CET 2003

>>>>> On Wed, 29 Jan 2003 14:12:15 +1300,
>>>>> Sam McClatchie (SM) wrote:

  > System info:
  > Mandrake 9.0
  > R Version 1.6.1
  > ESS 5.1.21
  > Emacs 21.2.1
  > -------------------

  > Colleagues

  > I've been calling R-code embedded in my LaTex document using Sweave, but 
  > would like to make things more convenient. At present as I understand it 
  >   you first process the R chunks of code using the Sweave function 
  > called from within R to process a "precursor file" e.g. foo.sw to get a 
  > LaTex file (foo.sw.tex) that you then process with latex foo.sw.tex.
  > ------------------------
  > example code segment

  > %\item {\bf Matched trawl and acoustic data} \label{real data}

  > \item {\bf Results}

  > %%%% sweave code

  > <<echo=false,results=hide>>=
  > average.trawl.spp.composition()
  > @

  > %%%% insert figure generated from sweave code
  > \begin{figure}
  > \includegraphics[scale=0.6]{../figures/bycatch_by_weight}
  > \caption{\label{catch by weight} Proportions of selected species (from
  >      Table \ref{ts length regressions}) in the fish assemblage using
  >      catch rate ($kg\ km{-1}$) as an approximation for fish density
  >      (neglecting variable capture efficiencies). Note: there were no
  >      oblique banded rattails in this dataset, although we have a
  >      \textit{<TS>-length} regression for them (see Table \ref{ts length
  >      regressions}). Box plot centre line = meadian, box limits are
  >      $25^{th}$ and $75^{th}$ quartiles, whiskers represent 1.5 times the
  >      interquartile range from the median, and points outside the whiskers
  >      are the tails of the distributions.}
  > \end{figure}
  > -----------------------

  > This works fine, but it is cumbersome for someone who likes to write a 
  > bit and then latex that additional bit. Of course I can just add the new 
  > LaTex code chunks to the foo.sw.tex and latex that, but I have to 
  > remember to copy the foo.sw.tex back to foo.sw or the versions get mixed 
  > up. Trivial, but annoying.

  > The question is: can I call the Sweave function from within LaTex so I 
  > just latex the foo.sw.tex and the Sweave chunks will also get processed. 
  > This would be much tidier.

  > One suspects that the short answer is 'no'.

One way to deal with this is to write several Sweave filew and collect
them into the main latex document using \input{} statements. Then you
can Sweave() only those files which have some changes, makefiles can
automate that easily.

I have some ideas on conditional processing of chunks and re-using
previously saved results in case nothing has changed, but that has not
been implemented yet.


                        Friedrich Leisch 
Institut für Statistik                     Tel: (+43 1) 58801 10715
Technische Universität Wien                Fax: (+43 1) 58801 10798
Wiedner Hauptstraße 8-10/1071      Friedrich.Leisch at ci.tuwien.ac.at
A-1040 Wien, Austria             http://www.ci.tuwien.ac.at/~leisch

More information about the R-help mailing list