[R-SIG-Mac] R script in batch mode on Mac

peter dalgaard pdalgd at gmail.com
Wed Nov 7 12:57:41 CET 2012


On Nov 7, 2012, at 12:08 , didier peeters wrote:

> Hi list,
> 
> I would like the run a R script in a batch mode.  So i use a command line like this :
> 
> for i in *.xlsx; do cat $i | echo 'argv <- $i; source("path/to/script.R")' | R --vanilla --slave ; done
> 
> which gives the error " Erreur : '$' inattendu(e) dans "argv <- $" "
> 
> i've also tried  :
> 
> for i in *.xlsx; do cat $i | R CMD BATCH --args $i "path/to/script.R" ; done
> 
> which gives me nothing.  
> 
> The idea is to read dozens of similar excel files in a folder with gdata package and to write their content in another single file.  
> My script works fine with a read.xls when i specify a file name, but and here I get the name of the file with :
> argv <- commandArgs(TRUE)
> 
> This is all I've been able to find from various docs and I'm not familiar with the command line.  
> What am I doing wrong ?
> Could anyone help me ?

You need to read up on shell command syntax. In particular, the "cat $i | command" bit would pipe the content of the file $i into the command, which makes no sense when the command is "echo" or "R". Also check up on the use of single and double quotes.


> 
> Didier
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-SIG-Mac mailing list