Skip to content
Prev 305939 / 398506 Next

Sweave - if \Sexpr{} than \SweaveInput{"my.Rnw"}

On 20/09/2012 8:47 AM, Witold E Wolski wrote:
The SweaveInput directives are processed before any expressions are 
evaluated, so you can't do it that way.  You can have Sweave chunks emit 
LaTex code, so this might achieve a similar effect:

<<results=tex>>=
if ( test ) name <- "my1"
else name <- "my2"

Sweave( paste0(name, ".Rnw") )
paste0("\\input{", name, ".tex}")
@

I've never tried having a Sweave chunk call Sweave(), so there might be 
troubles there, and you might only be able to input .tex files, not Rnw 
files.

Duncan Murdoch