An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110417/e8a12bd5/attachment.pl>
sweave options with variable
5 messages · Duncan Murdoch, Kai Ying, Gabor Grothendieck +1 more
On 11-04-17 2:41 AM, Kai Ying wrote:
hello:
Do any one know how to set sweave option by variable, for example I want
set some of my selected code chunk with:
<<eval=needRun>>= rather than<<eval=TRUE>>=, so I can change the action
only in the head by change the variable "needRun" one times.
I have tried use "\Def" and "\newcommand", both do not work, so I suppose it
is related with R/Sweave its self.
thanks for any good suggestion.
You can't do that, but you can get a similar effect this way:
<<echo=FALSE>>=
needRun <- TRUE
@
...
<<thecode,eval=FALSE>>=
someSlowFunction()
@
<<echo=FALSE>>=
if (needRun) {
<<thecode>>
}
@
Or you could use cacheSweave or weaver for caching, which may do what
you want, or write your own Sweave driver to do exactly what you want.
Duncan Murdoch
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110417/c6b665ca/attachment.pl>
On Sun, Apr 17, 2011 at 11:04 AM, Kai Ying <yingk at iastate.edu> wrote:
thanks, ? It can work but not as elegant as I expect because it add extra code to every chunk of code. I have tried the cache for this purpose it works in most case but have a lot of other problems so I decided to control it by myself. I guess that sweave running R code before tex, so tex variable do not work and need find something run before sweave and set the variable, but it seems currently no way do that. Write my own Sweave driver is too hard for me hope in the future someone can refine the sweave driver. ? best wishes
You may be better off just directly emit the latex from R (not using Sweave at all). Another alternative is the brew package.
Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
[Forgot to cc: the list] Hi.
On Sun, Apr 17, 2011 at 8:04 AM, Kai Ying <yingk at iastate.edu> wrote:
thanks, ? It can work but not as elegant as I expect because it add extra code to every chunk of code. I have tried the cache for this purpose it works in most case but have a lot of other problems so I decided to control it by myself. I guess that sweave running R code before tex, so tex variable do not work and need find something run before sweave and set the variable, but it seems currently no way do that.
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
Write my own Sweave driver is too hard for me hope in the future someone can refine the sweave driver. ? best wishes On Sun, Apr 17, 2011 at 7:30 AM, Duncan Murdoch <murdoch.duncan at gmail.com>wrote:
On 11-04-17 2:41 AM, Kai Ying wrote:
hello: ? ?Do any one know how to set sweave option by variable, for example I want set some of my selected code chunk with: <<eval=needRun>>= rather than<<eval=TRUE>>=, so ?I can change the action only in the head by change the variable "needRun" one times. I have tried use "\Def" and "\newcommand", both do not work, so I suppose it is related with R/Sweave its self. thanks for any good suggestion.
You can't do that, but you can get a similar effect this way:
<<echo=FALSE>>=
needRun <- TRUE
@
...
<<thecode,eval=FALSE>>=
someSlowFunction()
@
<<echo=FALSE>>=
if (needRun) {
<<thecode>>
}
@
Or you could use cacheSweave or weaver for caching, which may do what you
want, or write your own Sweave driver to do exactly what you want.
Duncan Murdoch
? ? ? ?[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.