Hello all and thanks in advance,
I know you can start R with either:
1. R CMD BATCH myfile.R
or
2. R < myfile.R
My question is this: what if I want multiple input files and/or command
line arguments. For example, under unix you can run a script command (in
a shell language, perl, or python) like:
python myScript.py
or better yet, if you have things set up right, you can place a
#!/usr/bin/python line at the beginning of the file and then just type (at
the shell command line):
./myScript.py
Now, if I wanted to specify a file to work with and a method to use, I
would just do:
./myScript.py file1 method1
How could I get this behavior in R? With the commandArg() function I can
retrieve the arguments at the command line, but I'm puzzling over the best
way to implement this system at the command line so that it will be
consistent regardless of how someone chooses to run the script (be it
method 1 or 2 above).
I suppose I could create a script file in {python, perl, bash, etc} that
would simply take the arguments I want and provide them to R in a uniform
manner but a "standalone" R method would be preferable.
Regards,
Mark
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Yet another batch mode question
3 messages · Mark E. Fenner, Brian Ripley
On Mon, 8 Oct 2001, Mark E. Fenner wrote:
Hello all and thanks in advance, I know you can start R with either: 1. R CMD BATCH myfile.R or 2. R < myfile.R
Um, you can't: try it to see the fatal error.
My question is this: what if I want multiple input files and/or command line arguments. For example, under unix you can run a script command (in a shell language, perl, or python) like: python myScript.py or better yet, if you have things set up right, you can place a #!/usr/bin/python line at the beginning of the file and then just type (at the shell command line): ./myScript.py Now, if I wanted to specify a file to work with and a method to use, I would just do: ./myScript.py file1 method1 How could I get this behavior in R? With the commandArg() function I can retrieve the arguments at the command line, but I'm puzzling over the best way to implement this system at the command line so that it will be consistent regardless of how someone chooses to run the script (be it method 1 or 2 above).
At present 1 does not pass along further arguments, but sends R method 2 (well, with enough flags to make it work). If you give 2 further arguments, you will get a strident warning like auk% R foo ARGUMENT 'foo' __ignored__ R : Copyright 2001, The R Development Core Team ...
I suppose I could create a script file in {python, perl, bash, etc} that
would simply take the arguments I want and provide them to R in a uniform
manner but a "standalone" R method would be preferable.
Your examples are entirely Unix, so I am not sure if you are interested in anything else, but R needs to be. Already on Windows R allows a file name to be used as an extra argument: this is needed for file associations and for drag-and-drop to work. We have considered allowing that on Unix too. so that R /path/to/.Rdata and R /path/to/somescript.R might work. (Only the first is implemented on Windows at present.)
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Tue, 9 Oct 2001, Prof Brian D Ripley wrote:
On Mon, 8 Oct 2001, Mark E. Fenner wrote:
Hello all and thanks in advance, I know you can start R with either: 1. R CMD BATCH myfile.R or 2. R < myfile.R
Um, you can't: try it to see the fatal error.
I did forget the "--no-save" or "--vanilla" or "--save" option that is required for #2 but otherwise: [mfenner at seneca testForList]$ cat test.R x <- array(trunc(3*runif(100)), c(10,10)) mean(x) [mfenner at seneca testForList]$cat results Script started on Tue Oct 9 09:41:52 2001 [mfenner at seneca testForList]$ R --no-save < test.R R : Copyright 2001, The R Development Core Team Version 1.3.1 (2001-08-31) <snip>
x <- array(trunc(3*runif(100)), c(10,10)) mean(x)
[1] 0.94
[mfenner at seneca testForList]$ R CMD BATCH test.R [mfenner at seneca testForList]$ more test.Rout R : Copyright 2001, The R Development Core Team Version 1.3.1 (2001-08-31) <snip>
invisible(options(echo = TRUE)) x <- array(trunc(3*runif(100)), c(10,10)) mean(x)
[1] 0.8
proc.time()
[1] 1.35 0.09 1.47 0.00 0.00
[mfenner at seneca testForList]$ exit Script done on Tue Oct 9 09:42:43 2001 [mfenner at seneca testForList]$ In short, they both work for me. You can supress the echoing of commands by placing a options(echo = FALSE) type line in your script file.
At present 1 does not pass along further arguments, but sends R method 2 (well, with enough flags to make it work). If you give 2 further arguments, you will get a strident warning like auk% R foo ARGUMENT 'foo' __ignored__ R : Copyright 2001, The R Development Core Team ...
So, do people not use R in this fashion under Unix (as a general rule)? That is, running R from the command line with a script and an input file. BTW, I am primarily interested in the Unix environment. Scripting under Windows raises my blood pressure :) (unless it is in cygwin). Regards, Mark -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._