In R (and C) \ must be escaped in a character string. This is mentioned on the help page.
On Tue, 30 Dec 2003, Itay Furman wrote: > > Hi, > > Am I missing something in using regexps in R? > Below, 'egrep' means invokation of the command from the shell > prompt. > > # I have > > as.character(block.dist.vals) > [1] "1e+06" "2e+06" "5e+06" > # that I wish to convert to: "1" "2" "5" > > # OK (R and egrep) > > sub( "e.+06", "", as.character(block.dist.vals) ) > [1] "1" "2" "5" > # OK (R), egrep will *not* match pattern > > sub( "e\\+06", "", as.character(block.dist.vals) ) > [1] "1" "2" "5" > > # egrep will match pattern; R will not. > > sub( "e\+06", "", as.character(block.dist.vals) ) > [1] "1e+06" "2e+06" "5e+06" > > As-far-as I can tell the last attempt should have worked, too. > Could someone explain to me why it doesn't? > > I have R 1.7.0 on RedHat 9. > > Thanks in advance, > Itay Furman > > ========================================================================= > Fred Hutchinson Cancer Research Center > email: [EMAIL PROTECTED] 1100 Fairview Avenue N., Mailstop D4-100 > phone: +1 (206) 667 5921 P.O. Box 19024 > fax: +1 (206) 667 2917 Seattle, WA 98109-1024 > > ______________________________________________ > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 ______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help