Skip to content
Prev 257134 / 398506 Next

sweave options with variable

[Forgot to cc: the list]

Hi.
On Sun, Apr 17, 2011 at 8:04 AM, Kai Ying <yingk at iastate.edu> wrote:
You can do exactly this by embedding your Sweave document with RSP markup, e.g.

<% needRun <- TRUE %>

<<eval=<%=needRun%>>>=
someSlowFunction()
@

To compile this into a valid Sweave document/file, you have to append
filename extension *.rsp, e.g. report.Rnw.rsp.  Then compile it as:

library("R.rsp");
rsp("report.Rnw.rsp", postprocess=FALSE);

which outputs a file report.Rnw containing:

<<eval=TRUE>>=
someSlowFunction()
@

If you also want to run Sweave on this and generate a PDF you can do
everything in one go (using the default postprocess=TRUE):

library("R.rsp");
rsp("report.Rnw.rsp");

RSP is a context-independent markup, i.e. it does not care what format
the underlying document has, as long as it is text based.

Hope this helps

/Henrik