Re: [R] gsub and "\"

From: jim holtman <jholtman_at_gmail.com>
Date: Wed, 09 Jul 2008 11:57:56 -0400

It does have a single \; the printing just shows that it is escaped. If you 'cat' it to output, you will see:

> gsub("'","\\\\'","abc's")

[1] "abc\\'s"
> cat(gsub("'","\\\\'","abc's"))

abc\'s

Which I think is what you were thinking it would be. So when you write it out to a file, it will be correct.

On Wed, Jul 9, 2008 at 11:49 AM, Sean Davis <sdavis2_at_mail.nih.gov> 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
>
> ______________________________________________
> 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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
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:13:47 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 - 16:31:34 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