R 64 bit on Mac OSX with ESS

[This article was first published on mpastell.com » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

So today I compiled 64 bit R 2.91 on Mac OS X   10.5.7 in order to get maximum speed for my analyses. The speed increase I got was 15-25 %, when I ran some tests with matrix calculation and intensive loops. Note that you can also download optimized binaries from  http://r.research.att.com/, although they are not the latest version. Update: This method also works with Snow Leopard 10.6.2 and R 2.10.0.

It took me some effort and googling to get it done so I’m going to post the instructions here, so that I know how to do it next time and I hope that it also benefits others. After I got the installation done I ran into a problem getting ESS to recognize my 64 bit version, but I managed to solve that as well. So here is how I did it:

Compiling

First I installed the necessary developer tools from http://r.research.att.com/tools/. I already had gcc 4.2 from apple so installed gfortran and libreadline readline-5.2-1-quad.tar.gz. Readline is a precompiled binary and you extract is using

sudo tar fvxz readline-5.2-1-quad.tar.gz -C /

After installing the depencies I extracted R-2.9.1.tar.gz downloaded from cran and executed configure in the extracted directory with the following options (a bit modified from http://r.research.att.com/building.html):

./configure SHELL=‘/bin/bash’ r_arch=x86_64
CC=‘gcc -arch x86_64 -std=gnu99’ CXX=‘g++ -arch x86_64’
OBJC=‘gcc -arch x86_64’ F77=‘gfortran -arch x86_64’
FC=‘gfortran -arch x86_64’ –with-system-zlib –with-blas=‘-framework vecLib’
–with-lapack –host=x86_64-apple-darwin9.7.0 –build=x86_64-apple-darwin9.7.0

After running “make” and “make install” I had a working installation that can be started using:

R –arch x86_64

Just running R tries to run 32 bit version of R which I don’t have, so I made an alias R=’R–arch=x86_64′ to .profile and R starts form terminal with just the familiar R.

Getting ESS to work

Ok, all was well so far but then I discovered that ESS can’t find R anymore, because it is trying to execute the 32 bit version and doesn’t work. So after looking at the ESS source I discovered that you can modify R startup options in the file  “essd-r.el“. I use Carbon Emacs, but this methods should work with other Emacs variants. If you are wondering how to install ESS on OS X have a look at this post.

First give yourself a permission to modify the file:

chmod u+w essd-r.el

Then open it and look for a line that says:

inferior-R-args ” ” ; add space just in case

And chance it to:

inferior-R-args “–arch x86_64 ” ; add space just in case

Thats it, you should now have a working ESS set up with a 64 bit R!

To leave a comment for the author, please follow the link and comment on their blog: mpastell.com » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)