[R] Sweave: multiline Sexpr?

Duncan Murdoch murdoch at stats.uwo.ca
Tue Jun 30 19:15:53 CEST 2009


On 30/06/2009 12:44 PM, David Huffer wrote:
> Is there any way to have Sexpr span multiple lines?

For input or output?  I.e. do you want

\Sexpr{x +
y}

or do you want the value to display on multiple lines?

I think you can't do the first.  To do the second, returning a character 
value with an embedded newline should work.  For example,

<<echo=FALSE>>=
string <- "this goes on \\\\\\\\\n two lines"
@
\Sexpr{string}

(I think you really need all those escapes to get two backslashes in the 
output!)

I don't know if it will happen for 2.10.x, but I would like to extend 
\Sexpr to be just as flexible as the <<>>= notation, by putting the 
Sweave options in a Latex-like option:

\Sexpr[fig=true]{ plot(rnorm(1000))}

You can do this now in R-devel in the new Sweave-like syntax in Rd files 
(except they don't support figs yet), but not yet in the original.

Duncan Murdoch




More information about the R-help mailing list