Skip to content
Prev 309285 / 398506 Next

export variable from bash to R

On Mon, Oct 29, 2012 at 10:43 AM, sophie <melanie.bieli at bluewin.ch> wrote:
Another replier has already suggested using commandArgs to get extra
arguments on the command line, but if you really want to push bash
variables through to R then you have to export them from bash and get
them using Sys.getenv in R:

$ export VARIABLENAME=a
$ R --slave
Sys.getenv("VARIABLENAME")
[1] "a"

(using R --slave to cut out all the startup messages etc)

Barry