[Rd] gsub + backslashes

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Apr 24 17:18:14 CEST 2006


On Mon, 24 Apr 2006, Torsten Hothorn wrote:

>
> Dear developeRs,
>
> I thought that backslashes can be escaped in the usual way (and I think I
> did this before) but I can't see why
>
> R> gsub("\\", "x", "\alpha")
> Error in gsub(pattern, replacement, x, ignore.case, extended, fixed,
> useBytes) :
>         invalid regular expression '\'
>
> gives an error. Or am I just blind?

Escape for R and escape for regexp:

> gsub("\\\\", "x", "\\alpha")
[1] "xalpha"

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
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



More information about the R-devel mailing list