From ripley at stats.ox.ac.uk  Mon Apr 24 17:18:14 2006
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Mon, 24 Apr 2006 16:18:14 +0100 (BST)
Subject: [Rd] gsub + backslashes
In-Reply-To: <Pine.LNX.4.64.0604241620370.12055@imbe153.imbe.med.uni-erlangen.de>
References: <Pine.LNX.4.64.0604241620370.12055@imbe153.imbe.med.uni-erlangen.de>
Message-ID: <Pine.LNX.4.64.0604241617220.31423@gannet.stats.ox.ac.uk>

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



[Rd] gsub + backslashes
Prof Brian Ripley