Re: [R] gsub and "\"

From: Ted Harding <Ted.Harding_at_manchester.ac.uk>
Date: Wed, 09 Jul 2008 17:06:44 +0100 (BST)


On 09-Jul-08 15:49:54, Sean Davis wrote:
> 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

In terms of the internal representation, I think you have in fact got what you want. It's just that when it's prented on the screen, the internal "\" is printed as "\\":

  nchar("abc\\'s")
  # [1] 6

  nchar("abc's")
  # [1] 5

Quite how you get it to be displayed as "abc\'s" is another matter, and I don't have an answer to it!

Ted.



E-Mail: (Ted Harding) <Ted.Harding_at_manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861
Date: 09-Jul-08                                       Time: 17:06:40
------------------------------ XFMail ------------------------------

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 09 Jul 2008 - 16:35:07 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 Jul 2008 - 17:31:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive