[R] A couple of batch mode questions
MacQueen, Don
m@cqueen1 @end|ng |rom ||n|@gov
Wed Jul 25 18:36:37 CEST 2018
From my perspective, which is a unix-alike perspective, Rscript makes R useable in exactly the same way as other unix style scripting languages such as perl, tcsh, bash, etc. This is useful, and a good thing. If I remember (and understood) correctly, it is why Rscript was introduced, later in R's history than BATCH.
Scripts run using Rscript can be (slightly) more self-contained, which I suppose might or might not be an advantage, depending on one's needs:
To run an R script using Rscript, I type
./myRscript.r
at the command line (less typing), whereas with batch mode, it has to be
R CMD BATCH myRscript.r
(more typing) but if I want any R options applied, such as --no-restore or --no-save, I include them within the script when using Rscript, but have to put them on the command line outside the script when using BATCH.
One can actually execute an R command at the shell prompt using Rscript, which can't be done with BATCH:
[296]% Rscript -e 3+4
[1] 7
[298]% Rscript -e 'sqrt(2)'
[1] 1.414214
If I want to pass custom parameters to the script (script-specific parameters of my own that I put on the command line), the syntax for either supplying them or parsing them might be different. I'm not sure, since I don't do this very often, and never use CMD BATCH. But it would be worth checking.
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
On 7/25/18, 8:22 AM, "R-help on behalf of Rich Shepard" <r-help-bounces using r-project.org on behalf of rshepard using appl-ecosys.com> wrote:
On Wed, 25 Jul 2018, Bert Gunter wrote:
> "Within R one can use source() to run a batch file of R commands, while R
> CMD BATCH and Rscript are run from the command line. Is this correct?"
>
> Yes.
Bert,
Thanks for confirming.
> I think your query answers your query: You use Rscript when you want to use
> R in the command environment, perhaps as part of an analytical pipeline;
> and you source an R file when you want to work within R.
That's a given. Why would I prefer Rscript over R CMD BATCH, or
vice-versa? I did not see much difference between the two in their help
files.
Regards,
Rich
______________________________________________
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list