From hb at biostat.ucsf.edu  Tue May 22 19:34:45 2012
From: hb at biostat.ucsf.edu (Henrik Bengtsson)
Date: Tue, 22 May 2012 10:34:45 -0700
Subject: [Rd] Best way to locate R executable from within R?
Message-ID: <CAFDcVCSbqCrF2hepKGC1n4BpdekBQcBg2B6+hSQFOZP9cgxq-g@mail.gmail.com>

Hi,

I'd like to spawn of a new R process from within R using system(),
e.g. system("R -f myScript.R").  However, just specifying "R" as in
that example is not guaranteed to work, because "R" may not be on the
OS's search path.

 What is the best way, from within a running R, to infer the command
(basename or full path) for launching R in way that it works on any
OS?  I came up with the following alternatives, but I'm not sure if
they'll work everywhere or not:

1. Rbin <- commandArgs()[1];

2. Rbin <- file.path(R.home(), "bin", "R");

Other suggestions that are better?

/Henrik



[Rd] Best way to locate R executable from within R?
Henrik Bengtsson