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
gsub and "\"
4 messages · jim holtman, Sean Davis, (Ted Harding)
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?
On Wed, Jul 9, 2008 at 11:57 AM, jim holtman <jholtman at gmail.com> wrote:
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.
Thanks, Jim. That does it. Sean
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?
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 ------------------------------