[R] R as shelll script

Alexandre Aguiar asaguiar at spsconsultoria.com
Wed May 28 02:28:09 CEST 2008


Hi,

I have devised some applications of R as a scripting shell language and 
started using it flawlessly a few months ago.

Never minded publishing it because it looked so obvious. However, a search 
in the archives revealed there is no recent easy-to-use method proposed. 
The latest reference I found is from 2006 
(http://finzi.psych.upenn.edu/R/Rhelp02a/archive/81124.html) and even a c 
wrapper has been proposed 
(http://kavaro.fi/mediawiki/index.php/Using_R_from_the_shell).

So, here it goes an exceedingly simple example of my simple solution that 
works pretty well:

#!/usr/local/bin/Rscript --vanilla
update.packages(ask=F, repos="http://cran.spsconsultoria.com")
# no need for calls to quit()

Now just chmod this properly (at least 700 is advisable) and you have an 
executable that can be run directly from the command line.

The --vanilla option is important to avoid dissemination of .History 
and .Rdata files in the system. But one can replace for another set of 
options to allow the load of .Rprofile, for instance (by 
using "--no-save  --no-restore  --no-site-file --no-environ" instead).

This has worked to me under several flavors of Linux and R since 2.2 or 2.4, 
not sure, do not remember (it must be that german guy the doctor said I 
can't remove from my mind :-).

Thanx for the existance of this list.

Alexandre

-- 
Alexandre Santos Aguiar, MD, SCT
--
website: http://spsconsultoria.com/
Phone: +55-11-3717-4866 (SP)
Phone: +55-21-3717-4866 (RJ)
Voicemail: +55-11-2157-6891 (SP)
Fax: +55-11-5549-8760 (SP)
--



More information about the R-help mailing list