From simon.urbanek at r-project.org  Tue May 22 20:07:55 2012
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Tue, 22 May 2012 14:07:55 -0400
Subject: [Rd] Best way to locate R executable from within R?
In-Reply-To: <CAF42j23wDpZ4TMPXk1eankBS7tcxETHaP-Bd4dvX9pvKR+sreA@mail.gmail.com>
References: <CAFDcVCSbqCrF2hepKGC1n4BpdekBQcBg2B6+hSQFOZP9cgxq-g@mail.gmail.com>
	<CAF42j23wDpZ4TMPXk1eankBS7tcxETHaP-Bd4dvX9pvKR+sreA@mail.gmail.com>
Message-ID: <CFEA7CD6-4B8C-479A-872E-3F5D958CB763@r-project.org>

On May 22, 2012, at 1:47 PM, Dan Tenenbaum <dtenenba at fhcrc.org> wrote:

> On Tue, May 22, 2012 at 10:34 AM, Henrik Bengtsson <hb at biostat.ucsf.edu> wrote:
>> 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?
> 
> Rbin <- file.path(Sys.getenv("R_HOME"), "bin", "R")
> 

That is certainly worse, not better.

1. doesn't work because it may be a relative path.

2. Sounds pretty good - since the environment will be set by the current R.


> Dan
> 
> 
>> 
>> /Henrik
>> 
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> 



[Rd] Best way to locate R executable from within R?
Simon Urbanek