From Simon.Urbanek at math.uni-augsburg.de  Sun Nov 30 21:38:03 2003
From: Simon.Urbanek at math.uni-augsburg.de (Simon Urbanek)
Date: Sun Nov 30 21:36:42 2003
Subject: [Rd] R as OS X Framework
In-Reply-To: <Pine.LNX.4.44.0311300729260.23674-100000@gannet.stats>
References: <Pine.LNX.4.44.0311300729260.23674-100000@gannet.stats>
Message-ID: <18438152-2375-11D8-A505-0003938AF008@math.uni-augsburg.de>

On Nov 29, 2003, at 9:33 PM, Prof Brian Ripley wrote:

> On Sat, 29 Nov 2003, Simon Urbanek wrote:
>
>> BTW: This is not Mac specific - I was fighting this on Windows (and
>> unix for that matter) as well - it is possible to run an .exe linked 
>> to
>> R.dll from anywhere, if R.dll is in the PATH. But then, one has to
>> determine R_HOME somehow (yes, there is the registry, but that's not
>> really safe if more R versions are installed).
>
> How do you do that?  For R's own executables on Windows R_HOME is
> determined from where they are loaded from.  You cannot AFAIK determine
> from within an executable where the R.dll was linked from.  That's why 
> the
> rproxy.dll uses the registry.  I believe you have even less 
> information on
> Windows.

On Mac OS X there is a very nice CoreFoundation function: 
CFBundleGetBundleWithIdentifier. Each bundle can have an unique 
identifier and the above function will return the bundle reference if 
the bundle was loaded by the current application - and a framework is a 
bundle. So for Mac OS X this piece of code will determine R_HOME of the 
linked R.framework:

CFBundleRef bundle = 
CFBundleGetBundleWithIdentifier(CFSTR("org.r-project.r-framework") );
CFURLRef rdir=CFBundleCopyBundleURL(bundle);
CFStringRef rhome=CFURLCopyFileSystemPath(rdir,kCFURLPOSIXPathStyle);

I doubt there is any standard way on unix platforms in general. I have 
a vague feeling that I saw some relevant API on Windows - at least form 
the DLL itself, but I'm stuck with my PowerBook for three more week 
until I get home, so I can't check that easily.

I would suggest a fallback for cases where the location cannot be 
determined: we could use a tiny source file like location.c.in (could 
be config.h.in itself for that matter) which gets processed by 
configure and contains the install path. Then any program linked to R 
shlib could call a function like char* R_installPath(); Although that 
is not optimal, it is in general unlikely that the user would move R 
after doing make install (unless it's a network installation of course 
- then we're in trouble) and it is even safer that the registry on 
Windows. It would be an useful fallback for platforms where we simply 
don't know.

Simon

PS: My script mentioned in the original post doesn't create proper 
Info,plist if ran by /bin/sh - you can get the correct Info.plist for R 
1.8.1 from http://stats.math.uni-augsburg.de/misc/Info.plist and copy 
it to .../R.framework/Resources/

---
Simon Urbanek
Department of computer oriented statistics and data analysis
Universit?tsstr. 14
86135 Augsburg
Germany

Tel: +49-821-598-2236
Fax: +49-821-598-2280

Simon.Urbanek@Math.Uni-Augsburg.de
http://simon.urbanek.info


[Rd] R as OS X Framework
Simon Urbanek