Re: [Rd] [R] shQuote and cat

2008-07-24 Thread Wacek Kusnierczyk
Duncan Murdoch wrote:
 Vadim Organovich wrote:
 It is precizely a shell command that I am trying to generate. To be
 specific let's try to have R 'output' the following shell command:
 'echo \a\'. This is is a valid command, at least in bash:
 bash-3.2$ echo \a\
 a

 Now in R:
  
 x - 'echo \a\'
 cat(x, '\n')
 
 echo a
  
 cat(shQuote(x), '\n')
 
 echo \\a\\

 Whichever way you do it it is not right. Again I think cat('echo
 \a\') should be printing *echo \a\* (asterics are not a part
 of the output)
   
try this:

(x = 'echo \\a\\') # or x = 'echo a')
[1] echo a

cat(x, \n)
# echo \a\

as desired.  you need to backslash the backslash.

vQ

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] [R] shQuote and cat

2008-07-23 Thread Vadim Organovich
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 [EMAIL PROTECTED]
Sent: Wednesday, July 23, 2008 1:10 PM
To: Vadim Organovich
Cc: [EMAIL PROTECTED]
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
 day26
 svn rev43537
 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]]

 __
 [EMAIL PROTECTED] 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.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] [R] shQuote and cat

2008-07-23 Thread Duncan Murdoch

On 7/23/2008 2:53 PM, Vadim Organovich wrote:

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.


It's not intended to be a string literal in R, it's intended to be input 
to the Windows CMD shell.  If you want a string literal in R, don't use 
cat().  cat() shows you the naked contents of the string without any 
quoting to make it a valid string literal.





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?


On Unix-like systems I think asking the shell to echo the output, i.e.

system(paste(echo, shQuote(input)), intern=TRUE)

is intended to reproduce the input.  However, the Windows CMD shell is 
different.  I don't know how to strip quotes off a string in it, e.g. I see


C:\WINDOWS\system32 echo a
a

Nevertheless, the quotes *are* necessary when passing filenames to 
commands, and they'll typically be stripped off when doing that, e.g.


echo hi a

will create a file named a, not named a, and

echo hi a b

will create a file with a space in the name.

Duncan Murdoch

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] [R] shQuote and cat

2008-07-23 Thread Vadim Organovich
It is precizely a shell command that I am trying to generate. To be specific 
let's try to have R 'output' the following shell command: 'echo \a\'. This 
is is a valid command, at least in bash:
bash-3.2$ echo \a\
a

Now in R:
 x - 'echo \a\'
 cat(x, '\n')
echo a
 cat(shQuote(x), '\n')
echo \\a\\

Whichever way you do it it is not right. Again I think cat('echo \a\') 
should be printing *echo \a\* (asterics are not a part of the output)


From: Duncan Murdoch [EMAIL PROTECTED]
Sent: Wednesday, July 23, 2008 2:38 PM
To: Vadim Organovich
Cc: r-devel@r-project.org
Subject: Re: [Rd] [R] shQuote and cat

On 7/23/2008 2:53 PM, Vadim Organovich wrote:
 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.

It's not intended to be a string literal in R, it's intended to be input
to the Windows CMD shell.  If you want a string literal in R, don't use
cat().  cat() shows you the naked contents of the string without any
quoting to make it a valid string literal.



 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?

On Unix-like systems I think asking the shell to echo the output, i.e.

system(paste(echo, shQuote(input)), intern=TRUE)

is intended to reproduce the input.  However, the Windows CMD shell is
different.  I don't know how to strip quotes off a string in it, e.g. I see

C:\WINDOWS\system32 echo a
a

Nevertheless, the quotes *are* necessary when passing filenames to
commands, and they'll typically be stripped off when doing that, e.g.

echo hi a

will create a file named a, not named a, and

echo hi a b

will create a file with a space in the name.

Duncan Murdoch

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.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] [R] shQuote and cat

2008-07-23 Thread Duncan Murdoch

Vadim Organovich wrote:

It is precizely a shell command that I am trying to generate. To be specific let's try to have R 
'output' the following shell command: 'echo \a\'. This is is a valid 
command, at least in bash:
bash-3.2$ echo \a\
a

Now in R:
  

x - 'echo \a\'
cat(x, '\n')


echo a
  

cat(shQuote(x), '\n')


echo \\a\\

Whichever way you do it it is not right. Again I think cat('echo \a\') should be printing *echo 
\a\* (asterics are not a part of the output)
  


But you were running on Windows, so the default shell is CMD, not bash.  
shQuote doesn't support bash specifically, but I imagine it uses the 
same quoting rules as sh, so you should use shQuote('a', type=sh).  
On my machine that gives 'a', and echo 'a' prints a as you wanted.


I don't think you want to quote the echo in the command, only the 
string that you want it to print, i.e. for the full command you should use


 cat(paste(echo, shQuote('a', type=sh)))
echo 'a'

Duncan Murdoch


From: Duncan Murdoch [EMAIL PROTECTED]
Sent: Wednesday, July 23, 2008 2:38 PM
To: Vadim Organovich
Cc: r-devel@r-project.org
Subject: Re: [Rd] [R] shQuote and cat

On 7/23/2008 2:53 PM, Vadim Organovich wrote:
  

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.



It's not intended to be a string literal in R, it's intended to be input
to the Windows CMD shell.  If you want a string literal in R, don't use
cat().  cat() shows you the naked contents of the string without any
quoting to make it a valid string literal.

  

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?



On Unix-like systems I think asking the shell to echo the output, i.e.

system(paste(echo, shQuote(input)), intern=TRUE)

is intended to reproduce the input.  However, the Windows CMD shell is
different.  I don't know how to strip quotes off a string in it, e.g. I see

C:\WINDOWS\system32 echo a
a

Nevertheless, the quotes *are* necessary when passing filenames to
commands, and they'll typically be stripped off when doing that, e.g.

echo hi a

will create a file named a, not named a, and

echo hi a b

will create a file with a space in the name.

Duncan Murdoch

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.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel



__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] [R] shQuote and cat

2008-07-23 Thread Simon Urbanek


On Jul 23, 2008, at 4:46 PM, Vadim Organovich wrote:

It is precizely a shell command that I am trying to generate. To be  
specific let's try to have R 'output' the following shell command:  
'echo \a\'. This is is a valid command, at least in bash:

bash-3.2$ echo \a\
a

Now in R:

x - 'echo \a\'
cat(x, '\n')

echo a

cat(shQuote(x), '\n')

echo \\a\\

Whichever way you do it it is not right.


Well, you input is not right ('\' is parsed in R into '') - you have  
to escape the backslash that you want to keep and all is well:


 x - 'echo \\a\\'
 cat(x, '\n')
echo \a\
 cat(shQuote(x), '\n')
'echo \a\'
 system(paste(sh -c,shQuote(x,type=sh)))
a

Cheers,
Simon


Again I think cat('echo \a\') should be printing *echo \a\*  
(asterics are not a part of the output)



From: Duncan Murdoch [EMAIL PROTECTED]
Sent: Wednesday, July 23, 2008 2:38 PM
To: Vadim Organovich
Cc: r-devel@r-project.org
Subject: Re: [Rd] [R] shQuote and cat

On 7/23/2008 2:53 PM, Vadim Organovich wrote:

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.


It's not intended to be a string literal in R, it's intended to be  
input
to the Windows CMD shell.  If you want a string literal in R, don't  
use

cat().  cat() shows you the naked contents of the string without any
quoting to make it a valid string literal.




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?


On Unix-like systems I think asking the shell to echo the output, i.e.

system(paste(echo, shQuote(input)), intern=TRUE)

is intended to reproduce the input.  However, the Windows CMD shell is
different.  I don't know how to strip quotes off a string in it,  
e.g. I see


C:\WINDOWS\system32 echo a
a

Nevertheless, the quotes *are* necessary when passing filenames to
commands, and they'll typically be stripped off when doing that, e.g.

echo hi a

will create a file named a, not named a, and

echo hi a b

will create a file with a space in the name.

Duncan Murdoch

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.


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel




__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel