Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.LNX.4.64.0604241617220.31423@gannet.stats.ox.ac.uk>
Date: 2006-04-24T15:18:14Z
From: Brian Ripley
Subject: gsub + backslashes
In-Reply-To: <Pine.LNX.4.64.0604241620370.12055@imbe153.imbe.med.uni-erlangen.de>

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