On Sat, Mar 9, 2013 at 9:32 PM, Yihui Xie <xie at yihui.name>
wrote:> See the example below (under Ubuntu):
>
> $ Rscript -e '1' -e '2'
> [1] 1
> [1] 2
> $ Rscript -e '1' -e '' -e '2'
> ERROR: option '-e' requires an argument
> $ uname -a
> Linux xie 3.5.0-25-generic #39-Ubuntu SMP Mon Feb 25 18:26:58 UTC 2013
> x86_64 x86_64 x86_64 GNU/Linux
>
> Similar problem under Windows:
>
> Rscript -e "1" -e "" -e "2"
> [1] 1
> Error: object 'e' not found
> Execution halted
>
> I can certainly save the code in a script and run Rscript foo.R, but
> I'm curious why Rscript stops when the -e argument is an empty string.
There's some over-zealous argument parsing in the main R startup
shell script. You didn't try negative numbers, did you?
$ Rscript -e "-1"
ERROR: option '-e' requires an argument
$ Rscript -e "+1"
[1] 1
The R script strips anything starting with a - from the arg after -e
and throws that error if there's nothing left. The relevant lines are:
-e)
if test -n "`echo ${2} | ${SED} 's/^-.*//'`"; then
a=`echo "${2}" | ${SED} -e 's/ /~+~/g'`; shift
else
error "option '${1}' requires an argument"
fi
- now at least that's on Unix. The Windows problem looks like its
doing something else, and mashing some quotes up and passing 'e' as an
expression to one of the other -e options.
Not sure what the fix might be, except maybe for the user to always
wrap their expressions in curly brackets...
Barry