5

I am using cacheSweave with a large LaTeX Sweave document. Rather than put

<<cache=true>>=
...snip...
@

in almost all of my code chunks, I would rather have cache=true be the default, and use

<<cache=false>>=
...snip...
@

when I don't want a code chunk to be cached. How can I set this default argument for code chunks?

I am currently using the following code to compile the Sweave document:

library(cacheSweave)
Sweave(infile, driver = cacheSweaveDriver)
David Robinson
  • 77,383
  • 16
  • 167
  • 187
  • 1
    for consistency with R, I recommend you to write TRUE/FALSE instead of true/false; as a side note, you can use either `opts_chunk$set(cache=TRUE)` or `\SweaveOpts{cache=TRUE}` in the knitr package (http://yihui.name/knitr), which also supports cache. – Yihui Xie Feb 22 '12 at 01:51

1 Answers1

7

There are a number of ways to accomplish this, but using \SweaveOpts{} to set the option somewhere early in your *.Snw file (e.g. in the document preamble) is probably the handiest:

\SweaveOpts{cache=TRUE}

As described in the Sweave manual, a \SweaveOpts{} statement anywhere in a documentation chunk will modify the defaults for "all code chunks after the statement".

A couple of other options are mentioned here.

Community
  • 1
  • 1
Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455