[R-SIG-Mac] Fully contained R.app

Simon Urbanek simon.urbanek at r-project.org
Sat Mar 8 20:37:15 CET 2008


Following the point brought up by Vince Carey, I thought I'll share  
some info how you can create a version of R that is fully contained in  
the R.app bundle. i.e. all you have is just the "R" icon that can be  
moved/copied anywhere.

Prerequisities:
- Mac OS X 10.4 or higher
- Xcode developer tools installed (see R for Mac FAQ)
- somewhat recent, working R.app + R framework (e.g. from CRAN) in  
default locations

For simplicity I assume that you'll be assembling the R on your  
Desktop and you are using regular CRAN binary, but you can do that  
anywhere with any R.

copy/paste in Terminal (I hope your mailer doesn't wrap this):

cd ~/Desktop
# copy R.app
ditto /Applications/R.app R.app
cd R.app/Contents
# copy the R.framework inside
mkdir Frameworks
ditto /Library/Frameworks/R.framework R.framework

# fix all executables and libraries
for f in `find . \( -perm +a+x -a -type f \)`; do
if otool -L $f 2>/dev/null|grep Versions/.../Resources/lib >/dev/null  
2>&1; then
libs=`otool -L $f 2>/dev/null|sed -n 's:.*\(/Library/Frameworks/ 
R.framework/Versions.*\) (.*:\1:p'`
for lib in $libs; do
nlib=`echo $lib|sed 's:/Library/Frameworks/R.framework/ 
Versions/...:@executable_path/../Frameworks/R.framework:'`
echo $f:$lib
install_name_tool -change $lib $nlib $f
done
fi
done

Now you have a fully working R.app on your desktop that you can copy  
anywhere and it is self-contained. All paths are relative to the  
executable, hence relative to R.app.

[Note: in order to test the fact that it is relocatable, you have to  
move/rename/delete /Library/Frameworks/R.framework first, otherwise  
rogue packages might fall back to that]

CAVEAT: There is a caveat, though: you *cannot* install any packages  
with such R. Installing source package is a no-no (they won't compile)  
and installing binary packages will only work if you fix them before  
use (i.e. cd into R.app/Contents and re-run the script above starting  
with "for f...")
[Another caveat is that the command-line version of such R won't work,  
but that is expected, because the R start script contains hard-coded  
R_HOME path, so you'd have to fix that whenever you move R.app.]

Therefore you should install all necessary packages (in the system- 
wide location) *before* you package it.

This is indented for those who wish to carry R with them on a USB  
stick temporarily and/or give a specifically setup version of R to  
others (class/workshop ...). It is not intended for "regular" use and  
is not officially supported. Use at your own risk ;).

Hint: to create a compressed disk image of this R such that you can  
use it without installing, run
cd ~/Desktop
mkdir R
mv R.app R
hdiutil create -srcfolder R R.dmg

Cheers,
Simon

For advanced users: you can also use install_name_tool -id to change  
the IDs of libraries in $R_HOME/lib. If you do that to your system R,  
all compiled packages will be correctly linked so you don't need the  
fixup anymore.



More information about the R-SIG-Mac mailing list