[OS X] R CMD INSTALL hdf5

Andy Jacobson andy.jacobson at noaa.gov
Fri Nov 7 12:47:23 EST 2008


Howdy,

I use R extensions (add-ons) extensively, and I've had marginal luck  
using the install.packages() function from within R.  This function  
seems to frequently find and install libraries for OS X that are of  
the wrong architecture.  Also, I don't always have an X11 connection  
to handle the pop-up "please select your mirror" window.

There's a command-line interface that allows you to install packages  
from source code.  I've found this to be in many ways superior:  not  
only do you stand a better chance of fixing any problems that crop  
up, but the act of downloading the source packages effectively  
creates a record of what I've actually installed.  This is  
tremendously helpful if you're in a situation of needing to work on  
multiple machines, or if you need to set up a new machine.

Here's a rather lengthy anecdote about today's installation of the  
'hdf5' package.  The first step in installing such a package is to  
find and download the source code:  go to CRAN > add-on packages >  
the page for your package.  In this case, drill down to http://cran.r- 
project.org/web/packages/hdf5/index.html.  Download the "package  
source" link, usually a tar.gz file.

As usual, the package's "configure" script was not smart enough to  
figure out that my hdf5 libraries were installed via fink in /sw/lib:

% R CMD INSTALL hdf5_1.6.7.tar.gz
* Installing to library '/Users/andy/Library/R/library'
* Installing *source* package 'hdf5' ...
checking for gcc... gcc
checking for C compiler default output file name... a.out
[lines deleted...]
checking for library containing H5open... no
configure: error: Can't find HDF5
ERROR: configuration failed for package 'hdf5'

"R CMD INSTALL --help" will explain that there are helpful "-- 
configure-vars" and "--configure-args" options that you can send to  
this command.  To make a long story short, the magic incantation in  
this case is:

R CMD INSTALL --configure-vars='CPPFLAGS=-I/sw/include' --configure- 
args='--with-hdf5=/sw' hdf5_1.6.7.tar.gz

There's no official documentation that I can find on how to use these  
options, but searching on "configure-vars" on the R mailing lists can  
give some examples.  The deal is that the "-vars" version is supposed  
to set environment variables for 'configure' to use, and the "-args"  
version allows you to specify options that the package authors have  
explicitly coded into the configure script.  (This 'configure' script  
business is part of the GNU autoconf tools.)

The R designers intend that cases like ours (i.e. prerequisites  
installed in /sw) could be handled using environment variables alone,  
setting LIBS and CPPFLAGS, as in:

R CMD INSTALL --configure-vars='LIBS=-L/sw/lib CPPFLAGS=-I/sw/ 
include' hdf5_1.6.7.tar.gz

This is a pretty clean design; it says that the configure script  
should, in addition to standard system directories, look in CPPFLAGS  
for the header (.h) files and in LIBS for the actual libraries.  In  
the case of the hdf5 package, however, this fails.  Some poking  
around in the guts of the package source showed to me that the reason  
for this is that the package authors didn't provide support for the  
LIBS variable.  I don't think end users should be expected to figure  
that out.

The next reasonable step is to untar the package and look at what  
explicit options have been coded into the configure script

% tar zxvf hdf5_1.6.7.tar.gz
% cd hdf5
% ./configure --help

This shows (among other stuff) that one option is:

  --with-hdf5=DIR        Use HDF5 installed in DIR

This is what gives us the right solution,

--configure-args='--with-hdf5=/sw'

I did need to read the "configure.in" file to see that LIBS was  
ignored (actually, overwritten), and to determine that "/sw" was the  
right directory, not "/sw/lib".  This also confirmed to me that a  
more standard environment variable, LDFLAGS, would also work:

R CMD INSTALL --configure-vars='LDFLAGS=-L/sw/lib CPPFLAGS=-I/sw/ 
include' hdf5_1.6.7.tar.gz

This does indeed succeed.  It's possible that LDFLAGS and CPPFLAGS  
would work for most UNIX systems like Mac OSX, but I'm not sure how  
far the R authors have gotten in pushings LIBS as a standard.

Cheers,

Andy

--
Andy Jacobson
andy.jacobson at noaa.gov

NOAA Earth System Research Lab
Global Monitoring Division
325 Broadway
Boulder CO 80305

303/497-4916





More information about the OSX mailing list