From edd @ending from debi@n@org  Mon Sep 17 13:37:46 2018
From: edd @ending from debi@n@org (Dirk Eddelbuettel)
Date: Mon, 17 Sep 2018 06:37:46 -0500
Subject: [Rd] Rscript -e does not accept newlines under Linux?
In-Reply-To: <c49909a1-68a9-020d-34a3-881100690326@gmail.com>
References: <D14049CE02C4F54D95360EEC06CE45C50F937902@SPMXM08.VUW.leidenuniv.nl>
 <c49909a1-68a9-020d-34a3-881100690326@gmail.com>
Message-ID: <23455.37386.987213.487828@rob.eddelbuettel.com>


On 17 September 2018 at 07:09, Duncan Murdoch wrote:
| 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.

When we wrote littler, ie 'r', just before Rscript was added to R itself, the
ability to work from standard input just like any other Unix tool does was in
fact a design feature.  So with littler it works (and you need -p to print as
we are silent by default by another design choice)

  edd at rob:~$ (echo "ls()"; echo "ls()")
  ls()
  ls()
  edd at rob:~$ (echo "ls()"; echo "ls()") | r -p
  [1] "argv"
  [1] "argv"
  edd at rob:~$

argv is a global variable to hold the arguments (as in C).

Hence standard things work the way you expect them to:

  edd at rob:~$ echo "set.seed(123); print(summary(rnorm(1e6)))" | r 
      Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
  -4.79919 -0.67439 -0.00026 -0.00052  0.67333  4.85077 
  edd at rob:~$ 

just like r -e ... would, or R -e do now.  It is harder to do this for R and
Rscript due to the way they are invoked, setting shell variables and all that
before calling into $R_HOME/exec/bin/R.

Dirk


-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org



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