Using R interactively provides immediate feedback on the success of commands issued, but is best suited to the development stage. Once you know these commands are working as expected, the next step is to incorporate them into an R script. You can call this script when you are in interactive mode to make sure your syntax and logic are correct, but once your R script runs in interactive mode, you may want to take advantage of the greater resources available by submitting a batch job. To do this, you will need to create a job script that calls your R script. Please see the detailed instructions or the documentation for Stampede2 or Frontera about using sbatch for submitting a job with Slurm; the following exercise gives a simple example.

Your job script needs to load the R module and cd to the directory where your R script resides. Alternatively, you can specify the complete path to your R script. To run an R job in batch mode you need to use the following syntax in your batch file:

The default options for the R workspace include --restore and --save. A list of the available options is given in Appendix B of An Introduction to R (PDF). The opposites of the default options are --no-restore and --no-save. Two of the more useful options are --quiet, which will suppress printing of the R commands in the script and --no-timing which prevents R from printing the computational time for the job.

R assumes the infile is in the same directory as the job script, so the complete path might need to be supplied. The same applies to the outfile. If you don't specify an output file, the file name is derived from the name of the R script plus .Rout.

There is another way to invoke R in batch mode using instead of R CMD BATCH. It does not take any options and any output from the job will be put into .

 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Access Statement