Skip to content

I want to use Sweave, but only sometimes

5 messages · Paul Johnson, Duncan Murdoch, cls59 +1 more

#
Does anybody have a workable system to run an Rnw document through
R-Sweave when necessary, but to just run it through LaTeX if no new R
calculations are needed? I.e.,  the figures already exist, I do not
need R to do more work for me, so I send the document straight to
LaTeX.

I want to leave open the option that I might need to run the document
through Sweave in the future, so I don't want to just convert the
document to pure LaTeX format.

Here's why I think this must be possible. In this list, I saw one of
you explain this approach to working with figures in Sweave docs:

Instead of using the automatic figure inclusion approach like this:

<<testfn2, fig=true>>=
curve(sin, from = 1, to = 55)
@

Do this instead:


\SweaveOpts{prefix.string=foo/bar}

<<testfn2, fig=true, include=false>>=
curve(sin, from = 1, to = 55)
@


\begin{figure}
\caption{My Figure}
\includegraphics{foo/bar-testfn}
\end{figure}


As long as the figures are saved in the directory foo, then LaTeX will
find them, I think (hope!).  Then if I could tell LaTeX to ignore the
<<>> ...@ stuff, then it *seems* to me the Rnw file would be processed
successfully without further hassle.

I am sorry if this has been asked & answered before, I may not know
the "magic words" for searching for past solutions.

pj
#
On 4/13/2009 2:07 PM, Paul Johnson wrote:
It's not exactly what you asked for, but the weaver package goes some 
way towards that, by caching the results of code chunks and not 
recomputing them.

weaver is on Bioconductor, not CRAN, so you can install it using

     source("http://bioconductor.org/biocLite.R")
     biocLite("weaver")

An alternative approach is to save the slow calculations manually, and 
then load() an image in an early chunk, and proceed from there.  But if 
it's your figures that take a long time, that might not help.  I'm not 
sure that weaver caches figures, but I would guess so.

Duncan Murdoch
#
Paul Johnson-11 wrote:
The cacheSweave package does just that. A friend and I are also working on
another package called pgfSweave that incorporates code chunk caching along
with native compilation of R graphics output inside LaTeX so there are no
font differences. cacheSweave is available from CRAN and has been released
for a while now. Currently pgfSweave is only available from rforge.net and
is very much in beta. Hopefully things will really get moving this summer.

If you want to turn a .Rnw file into a plain LaTeX file, just run it through
Sweave('myPaper.Rnw') from the R command line. This creates myPaper.tex
which contains all the output and none of the << >>= @ chunk operators.

Also, your intuitions about the \SweaveOpts{prefix.string=figs/} command are
correct- this does specify a subfolder for figure output to reside in. Just
make sure you have created the folder yourself before running Sweave
otherwise it will give an error.

Hope that helps!

-Charlie

-----
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University