[R] Sweave, backslash in sub pattern? was: Backslash in sub pattern?

Stephan Kolassa Stephan.Kolassa at gmx.de
Mon Jul 14 20:59:25 CEST 2008


Duncan,

thank you, that works perfectly! And a big thank you also to all others 
who helped! I'm back to Sweaving!

Best wishes
Stephan


Duncan Murdoch schrieb:
> 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
>



More information about the R-help mailing list