Skip to content

R script in batch mode on Mac

3 messages · didier peeters, Peter Dalgaard, Berend Hasselman

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

            
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.

  
    
#
On 07-11-2012, at 12:08, didier peeters wrote:

            
Try Rscript like this

for k in *.R; do
    Rscript -e "source('path/to/script.R')" $k
done

and get the name of the file to process from commandArgs()

or

Rscript -e "source('path/to/script.R')" *.xlsx

and loop over the elements of commandArgs() in the script.

or

use list.files() -- something like list.files(pattern="^.*\\.xlsx") -- in the script then you don't need to loop in the shell script.

Berend