Skip to content
Prev 278699 / 398503 Next

Running Shell Script with R

Hi John,

Hard to say (for me) what's going on ... is there any errors in any
relevant logs anywhere?

Also, note that you don't have to write a bash script to run your R
script .. you can write a script with a shebang like so:

=====================
#!/usr/bin/env Rscript

## R code here.
=====================

And the R code will run as a command line script .. maybe that can
prove helpful in your situation. When doing so, I find it helpful to:

(1) To set R to exit when some error happens in your code you didn't
account for. In "shell/Rscript" mode (or whatever we call it), I've
found that when an error happens, the script just goes through to the
next command. To get R to do so, I set the appropriate options() at
the top of my script like so:

options(error=function(err) {
  cat("An error happened you didn't account for\n")
  cat("\n\n")
  quit(save='no', status=1)
})

(2) I find it handy to use the optparse package from CRAN to help
parsing command line arguments and options/flags:

http://cran.r-project.org/web/packages/optparse/index.html

HTH,
-steve
On Mon, Nov 28, 2011 at 11:10 AM, jp134711 <johnandrewpura at gmail.com> wrote: