[R] gsub and "\"

Sean Davis sdavis2 at mail.nih.gov
Wed Jul 9 17:49:54 CEST 2008


This is hopefully a simple question.  I am trying to escape single
quotes like so:

abc's   >> abc\'s

However, I cannot find an easy way to do that with gsub:

gsub("'","\\\\'","abc's")
# returns "abc\\'s"

How can I get a single \ in the output?

Thanks,
Sean



More information about the R-help mailing list