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

From: Stephan Kolassa <>
Date: Mon, 14 Jul 2008 20:59:25 +0200


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

Best wishes

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
> mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon 14 Jul 2008 - 19:12:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 14 Jul 2008 - 20:33:47 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive