[Rd] [R] shQuote and cat

Vadim Organovich vogranovich at jumptrading.com
Wed Jul 23 20:53:04 CEST 2008


I feel like it now belongs to r-devel more than to r-help.

My output was garbled because I sent the original message as HTML, sorry about that.

Your output, "\"\\"a\\"\"", is what I get too. That is
 > cat(shQuote(shQuote(shQuote("a"))), '\n')
"\"\\"a\\"\""
, which I think should be "\"\\\"a\\\"\"".

Actually, the R's output, "\"\\"a\\"\"", is not even a valid string literal, that is
> x <- "\"\\"a\\"\""
fails.


Now, by cat() being the inverse of shQuote() I mean printing the same literal as it goes into shQuote, quotes included:
> cat(shQuote("a"), '\n')
"a"

whereas
> cat("a", '\n')
a  ## no quotes

If cat() is not the inverse of shQuote() in the above sense, what is?

Thanks,
Vadim
________________________________________
From: Duncan Murdoch [murdoch at stats.uwo.ca]
Sent: Wednesday, July 23, 2008 1:10 PM
To: Vadim Organovich
Cc: r-help at r-project.org
Subject: Re: [R] shQuote and cat

On 7/23/2008 12:20 PM, Vadim Organovich wrote:
> Dear R-users,
>
> It is my understanding that cat(shQuote(a.string)) should print the origintal a.string. Is this right?

No, cat(a.string) should print the original a.string.  shQuote(a.string)
adds quotes so that a.string can be used in the shell.

> I am not sure cat() correctly prints strings which are generated by triple-shQuote():
>
>> shQuote(shQuote("a"))
> [1] "\"\\\"a\\\"\""
>> cat(shQuote(shQuote(shQuote("a"))), '\n')
> "\"\\"a\\"\<file://\\"a\\"\>""

That's a very strange result.  I tried the obsolete version of R that
you're using, and I didn't see it. I get this:

 > cat(shQuote(shQuote(shQuote("a"))), '\n')
"\"\\"a\\"\""

Duncan Murdoch

> As you can see the latter string has fewer quoting '\' than the former.
> cat() of double shQuote works as expected:
>
>> shQuote("a")
> [1] "\"a\""
>> cat(shQuote(shQuote("a")), '\n')
> "\"a\""
>> version
>                _
> platform       i386-pc-mingw32
> arch           i386
> os             mingw32
> system         i386, mingw32
> status
> major          2
> minor          6.1
> year           2007
> month          11
> day            26
> svn rev        43537
> language       R
> version.string R version 2.6.1 (2007-11-26)
> Am I missing something?
>
> Thanks,
> Vadim
>
> ________________________________
> Note: This email is for the confidential use of the named addressee(s) only and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you are hereby notified that any review, dissemination or copying of this email is strictly prohibited, and to please notify the sender immediately and destroy this email and any attachments. Email transmission cannot be guaranteed to be secure or error-free. Jump Trading, therefore, does not make any guarantees as to the completeness or accuracy of this email or any attachments. This email is for informational purposes only and does not constitute a recommendation, offer, request or solicitation of any kind to buy, sell, subscribe, redeem or perform any type of transaction of a financial product.
>
>       [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.

Note: This email is for the confidential use of the named addressee(s) only and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you are hereby notified that any review, dissemination or copying of this email is strictly prohibited, and to please notify the sender immediately and destroy this email and any attachments.  Email transmission cannot be guaranteed to be secure or error-free.  Jump Trading, therefore, does not make any guarantees as to the completeness or accuracy of this email or any attachments.  This email is for informational purposes only and does not constitute a recommendation, offer, request or solicitation of any kind to buy, sell, subscribe, redeem or perform any type of transaction of a financial product.



More information about the R-devel mailing list