[Rd] Rscript -e does not accept newlines under Linux?
murdoch@dunc@n @ending from gm@il@com
Mon Sep 17 13:09:32 CEST 2018
On 16/09/2018 4:53 AM, Voeten, C.C. wrote:
> 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()
> 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()
> ARGUMENT 'ls()' __ignored__
> 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()
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()'
And I see this, which may explain the original problem:
$ Rscript -e 'commandArgs(); ls()'
Notice that argument 5 includes both commands, whereas with the newline
they are separated:
$ Rscript -e 'commandArgs()
ARGUMENT 'ls()' __ignored__
And finally, this also works:
Rscript -e 'ls()
More information about the R-devel