title: Running an R file with arguments from a bash script
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2151212/how-can-i-read-command-line-parameters-from-an-r-script">How can I read command line parameters from an R script?</a>  </p>
  </blockquote>
  
  
  
  <p>I've got a R script for which I'd like to be able to supply several command-line parameters (rather than hardcode parameter values in the code itself). The script runs on linux.</p>
  
  <p>I can't find out how how to read the R.script on the command line Bash.</p>
  
  <p>sh file</p>
  
  <pre><code>cd `dirname $0`
  /usr/lib64/R/bin/R --vanilla --slave "--args input='$1' input2='$2' output='$3'"  file=/home/lvijfhuizen/galaxy_dist/tools/lisanne/partone.R  $3.txt
  </code></pre>
  
  <p>R file</p>
  
  <pre><code>args &lt;- commandArgs()
  file &lt;- read.csv(args[8],head=TRUE,sep="\t")   
  annfile &lt;- read.csv(args[9],head=TRUE,sep="\t")
  </code></pre>