Skip to content

Getting arguments from command line to run a R script

2 messages · Etienne Toffin, Brian Ripley

#
Hi,

I use a command line C++ program to run stochastic simulations.

With a shell script I run my program several parameter values and use  
the command
R CMD BATCH ../PlotDigging.r
where PlotDigging.r is a R file that plot several graphics from my  
simulation results and write a .png file.

Right now I just enter parameter values both in my shell script and my  
R file : that way I can't launch that much values. So I would like to  
know if there's a way to launch R CMD as I already do and give it the  
parameter values entered in the shell script?

Hope I'm clear enough to get an answer?

Thanks,

Etienne

-------------------------------------------------------------------
Etienne Toffin, PhD Student
Unit of Social Ecology
Universit? Libre de Bruxelles, CP 231
Boulevard du Triomphe
B-1050 Brussels
Belgium

Tel: +32(0)2/650.55.30
Fax: +32(0)/650.59.87
Skype: etienne_titou
http://www.ulb.ac.be/sciences/use/toffin.html
#
This is not specific to Mac OS X.

See ?commandArgs and the --args argument to R.

Something that is specific to Mac OS X is that the most convenient way to 
do this is to use Rscript, and I understand that is not installed into the 
standard path on the CRAN binary.  It is I think at

/Library/Frameworks/R.framework/Resources/bin/Rscript

See ?Rscript for how to use it.
On Mon, 26 May 2008, Etienne Toffin wrote: