[Rd] Rscript -e does not accept newlines under Linux?

Tomas Kalibera tom@@@k@liber@ @ending from gm@il@com
Mon Oct 8 17:05:16 CEST 2018


I've checked in an experimental fix for this (75413). The newline was 
lost in the shell script wrapper for R, it is now being escaped 
similarly to space. To pass multiple commands to Rscript, one can also 
use "-e" multiple times.

Tomas

On 09/17/2018 01:09 PM, Duncan Murdoch wrote:
> On 16/09/2018 4:53 AM, Voeten, C.C. wrote:
>> Hello,
>>
>> I have found what I believe to be a bug in the Linux version of the 
>> Rscript binary.
>> Under Windows (official 64-bit 3.5.1 R distribution running on an 
>> up-to-date Win10), I can do the following (e.g. under powershell):
>>
>> PS H:\Users\Cesko> Rscript -e 'ls()
>>>> ls()'
>> character(0)
>> character(0)
>>
>> which works as I expect: I am running Rscript with two arguments, 
>> namely (1) '-e', and (2) two lines of code to be run, and it indeed 
>> executes those two lines of code.
>>
>> This fails when attempted on a Linux build (amd64, compiled from the 
>> official 3.5.1 sources, but also reproducible with today's r-devel 
>> snapshot):
>>
>> $ Rscript -e 'ls()
>> ls()'
>> ARGUMENT 'ls()' __ignored__
>>
>> character(0)
>>
>> This behavior is not what I expected. Have I found a bug, or am I 
>> simply using it wrong?
>
> I would not assume that shell behaviour in Windows and Unix would 
> always be the same.  A better comparison would be to list some other 
> command on the same system that behaves differently.  For example, on 
> MacOS I see
>
> $ echo 'ls()
> > ls()'
> ls()
> ls()
>
>
> which suggests that what you wrote should be legal, but the form of 
> that command is different: there's no equivalent of "-e". Maybe 
> someone else who knows Unix shell behaviour better can comment on 
> whether they'd expect your Rscript command to work.
>
> By the way, if you just want multiple commands to execute, you can 
> separate them by semi-colons, and that does work:
>
> $ Rscript -e 'ls(); ls()'
> character(0)
> character(0)
>
> And I see this, which may explain the original problem:
>
> $ Rscript -e 'commandArgs(); ls()'
> [1] "/Library/Frameworks/R.framework/Resources/bin/exec/R"
> [2] "--slave"
> [3] "--no-restore"
> [4] "-e"
> [5] "commandArgs();~+~ls()"
> character(0)
>
> Notice that argument 5 includes both commands, whereas with the 
> newline they are separated:
>
> $ Rscript -e 'commandArgs()
> > ls()'
> ARGUMENT 'ls()' __ignored__
>
> [1] "/Library/Frameworks/R.framework/Resources/bin/exec/R"
> [2] "--slave"
> [3] "--no-restore"
> [4] "-e"
> [5] "commandArgs()"
> [6] "ls()"
>
> And finally, this also works:
>
> Rscript -e 'ls()
> -e
> ls()'
>
>
> Duncan Murdoch
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list