Skip to content
Prev 169468 / 398506 Next

Sweave and backslashes

On Thu, 5 Feb 2009, cls59 wrote:

            
The syntax Sweave uses is fairly sensitive to backslashes. I might guess 
that this is a feature to protect against runaway expressions.

You need to add a backslash to undo what Sweave does to the backslashes in 
that type of expression.

Put

  	extra.slash <- function(x) sub('\\','\\\\', x, fixed=TRUE)

in an earlier code chunk and then call

 	\Sexpr(extra.slash( latexNum( 4*10^3 ) ) )

or better still just use a code chunk like this:

@
<<echo=F,results=tex>>
cat( latexNum( 4*10^3 ) )
@ %def

HTH,

Chuck
Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901