[R] Backslash in sub pattern?

From: Stephan Kolassa <Stephan.Kolassa_at_gmx.de>
Date: Mon, 14 Jul 2008 20:09:27 +0200


Dear guRus,

I am trying to replace "~" by "$\sim$" for TeX. However, I can't get the backslash to work. I would like to turn "DV~IV" into "DV$\sim$IV".

sub("~","$\sim$","DV~IV") => "DV$sim$IV"
sub("~","$\\sim$","DV~IV") => "DV$sim$IV"
sub("~","$\\\sim$","DV~IV") => "DV$sim$IV"
sub("~","$\\\\sim$","DV~IV") => "DV$\\sim$IV"

Alternatives 1 and 3 also yield warnings about unknown escape sequences (no surprise there). I have been unsuccessfully searching the archives. sessionInfo below.

Thank you all for your time!

Best regards
Stephan

> sessionInfo()

R version 2.7.1 (2008-06-23)
i386-pc-mingw32

locale:
LC_COLLATE=German_Germany.1252;LC_CTYPE=German_Germany.1252;LC_MONETARY=German_Germany.1252;LC_NUMERIC=C;LC_TIME=German_Germany.1252

attached base packages:
[1] stats graphics grDevices utils datasets tcltk methods

   base

other attached packages:
[1] svIDE_0.9-5

loaded via a namespace (and not attached): [1] svMisc_0.9-5



R-help_at_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. Received on Mon 14 Jul 2008 - 18:14:20 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 - 19:31:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive