.comment-link {margin-left:.6em;} <$BlogRSDURL$>

Wednesday, September 28, 2005


So for work I need to be able to do some statistical analysis using the R programming language (a language optimized for statistics. It is an open source implementation of the proprietary language S. Yes, computer people are weird). But most of what I'm doing is written in Python. There is a Python module called rpy that allows the Python programmer to do stuff in R and get back Python objects. It doesn't get much cooler than that.

But, getting all that set up is non-trivial. Especially if you're doing this all on a Macintosh. The Macintosh is almost Unix but with enough differences to throw the User a few curves from time to time. One of the differences is that the Mac prefers to have programs built as 'frameworks' (don't ask, just accept it). There is a howto on building R on the Mac that gives the direction for doing just that. The main take-home from the howto is the options for configure:

./configure --with-blas='-framework vecLib' --with-lapack --with-aqua
The rest is vanilla make and sudo make install. But to build rpy you need to build R as a shared library. This means, according to the rpy README, that you should add --enable-R-shlib to the R ./configure line.

Building rpy is pretty easy:

export RHOMES
python setup.py build
sudo python setup.py install
But if you do that you pretty quickly fail with
ld: can't locate file for: -lRlapack
error: command 'gcc' failed with exit status 1
If you look in /Library/Frameworks/R.framework/Resources/modules you will find lapack.so which seems like it should do the trick. You can modify the setup.py to look at that lapack.so, but it just won't work. You can then tear your hair out for a while. At some point before you go bald you should note that the setup.py is looking for Rlapack not lapack. At this point you're desperate so you delete the entire R build and start over with this configure line:
./configure --with-blas='-framework vecLib'  --with-aqua --enable-R-shlib
Looking in /Library/Frameworks/R.framework/Resources/lib will show you Rlapack.dylib! Try the rpy build over again and now you succeed! Wahoo!

I'm having a bit of trouble generating graphics, but the basic R functionality seems to be visible from Python. Life is full.

Comments: Post a Comment

Links to this post:

Create a Link

This page is powered by Blogger. Isn't yours?