On 7/14/2008 2:39 PM, Stephan Kolassa wrote:
Phil:

thanks a lot! However, my original problem[1] remains: in fact, I am trying to \Sexpr the result for Sweave, and for some reason Sweave regurgitates the \Sexpr command unchanged:

foo.Rnw contains:
\Sexpr{"DV~IV"}
\Sexpr{cat("DV~IV")}
\Sexpr{sub('~','$\\\\sim$',"DV~IV")}
\Sexpr{cat(sub('~','$\\\\sim$',"DV~IV"),"\n")}


The \Sexpr{} form is limited in what it can handle; it's probably getting confused by all those escapes. Here's a way to do it that works for me:

<<>>=
Fixtilde <- function(x) sub('~','$\\\\\\\\sim$',x)
@

Here it is:  \Sexpr{Fixtilde("DV~IV")}.


I haven't traced through the code to see why I need 8 escapes so that one makes it through to the .tex file, but that's what appears to work.

Duncan Murdoch

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to