Skip to content
Prev 305978 / 398506 Next

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

On 20/09/2012 9:05 AM, Duncan Murdoch wrote:
I was curious, so I tried this.  It's fine to run Sweave in a code 
chunk, but it prints a fair bit by default, so the chunk up above won't 
work exactly as written.  You need to cat() the \input line, and tell 
Sweave not to print anything, or just ignore what it prints.  I think  
this would do it:

<<echo=false, results=tex>>=

if ( test ) name <- "my1"

else name <- "my2"

Sweave( paste0(name, ".Rnw"), quiet=TRUE )

cat( paste0("\\input{", name, ".tex}") )

@


Duncan Murdoch