Skip to content
Back to formatted view

Raw Message

Message-ID: <505B147E.2010406@gmail.com>
Date: 2012-09-20T13:05:02Z
From: Duncan Murdoch
Subject: Sweave - if \Sexpr{} than \SweaveInput{"my.Rnw"}
In-Reply-To: <CAAjnpdiq+Piuz+jhWZZgvo5Xi22ypQ-jv-aP0NSOiaOe69m96Q@mail.gmail.com>

On 20/09/2012 8:47 AM, Witold E Wolski wrote:
> Depending on an R computation I would like to include an Sweave documents
> in the main Sweave document.
> How can I do it?
>
> So I was thinking .... to use Latex features :
>
> \newif\ifpaper
>
> \ifpaper
>
> \SweaveInput{"my1.Rnw"}
> \else
>   \SweaveInput{"my2.Rnw"}
> \fi
>
> But how do I set paper to true or false given an \Sexpr ??
>
> \papertrue % or
>
> \paperfalse
>
>
> Any ideas?

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