title: How to submit an R script to a job scheduler: bash, compiler, Rscript, or other?
body: <h3>My Problem:</h3>
  
  <p>I have an R script <code>myscript.R</code> that uses a configuration file, e.g. <code>config.xml</code>, what is the best way to submit such a script to a job scheduler (e.g., using qsub)?</p>
  
  <p>I would like to be able to use the script and file in the same way that I would use, e.g., a C or Fortran executable, which is embedded in a bash script.</p>
  
  <h3>How I currently use FORTRAN:</h3>
  
  <p>Here is an example of the approach that I use with a compiled Fortran executable <code>fex</code> like the following that I will call <code>fscript.sh</code>:</p>
  
  <pre><code>!#/bin/bash/
  mpirun [arguments] "fex" -f $1
  </code></pre>
  
  <p>The above <code>fscript.sh</code> can be sent to a cluster with instructions to read the config file like this:</p>
  
  <pre><code>qsub [arguments] fscript.sh 1 config.xml
  </code></pre>
  
  <h3>How I currently use R in an analogous way:</h3>
  
  <p>To run R in an analogous way, I am using a bash script <code>rscript.sh</code></p>
  
  <pre><code>#!/bin/bash
  CONFIG=$1
  env $CONFIG R --vanilla &lt; myscript.R
  </code></pre>
  
  <p>This can be run at the command line, e.g.</p>
  
  <pre><code>qsub [arguments] rscript.sh config.xml
  </code></pre>
  
  <p>Where the <code>rscript.R</code> contains something like</p>
  
  <pre><code>library(XML)
  config &lt;- Sys.getenv("CONFIG")
  config &lt;- xmlList(xmlParse(config.xml))
  myfunction(config)
  </code></pre>
  
  <h3>My Questions</h3>
  
  <ol>
  <li>Would Rscript or compiler provide a more robust approach than my current use of bash?</li>
  <li>Under which conditions would one be more appropriate than the other (What are the pros and cons)?</li>
  <li>How would I pass a configuration file in either case?</li>
  </ol>
  
  <h3>What I have done so far</h3>
  
  <p>In addition to coming up with the bash script <code>rscript.sh</code> described above, I have read through tutorials and some documentation for <a href="http://blog.revolutionanalytics.com/2009/01/using-r-as-a-scripting-language-with-rscript.html" rel="nofollow noreferrer"><code>Rscript</code></a> and <a href="http://dirk.eddelbuettel.com/blog/2011/04/12/#the_new_r_compiler_package" rel="nofollow noreferrer">compiler</a>, but it is not clear to me if these are the contexts in which one would be preferred over the other. Also, it is not clear the best way to pass a configuration file in either context. </p>
  
  <p>This questions is related to others, e.g., <a href="https://stackoverflow.com/questions/4918553/what-are-the-ways-to-create-an-executable-from-r-program?lq=1">What are the ways to create an executable from R program</a>, <a href="https://stackoverflow.com/questions/1452235/does-an-r-compiler-exist">Does an R compiler exist?</a>. However, I do not think that is essential to use compiled code.</p>