[R] detect escape character

Sarah Goslee sarah.goslee at gmail.com
Tue Jun 3 20:18:14 CEST 2014


Hi,

R uses \ as a metacharacter, so you need a non-intuitive number of \:


mystring <- "Man\\Woman"
# \\ is a metacharacter and a \, so it's equivalent to \ in normal text
sub("\\\\", "/", mystring)


Sarah


On Tue, Jun 3, 2014 at 2:03 PM, Adrian Dușa <dusa.adrian at unibuc.ro> wrote:
> Dear All,
>
> I should be knowing this, but not get it right... For a string like this:
>
> "Man\Woman"
>
> I would like to detect the escape character "\" and replace it with "/".
>
> Tried various ways using gsub(), but don't get it right yet. Any suggestion
> would be highly welcomed...
>
> Thank you,
> Adrian
>

-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list