17 July 2014

Setup R with Homebrew on Mac OS X

On 1st of September a new course about Data Analysis and Statistical Inference starts. The course uses R - a system for statistical computing.

Get it on Mac OS X

The easies way to get open source tools on Mac OS X is using Homebrew. But there is an additional dependency for R, which is not provided by Homebrew: XQuartz. Download and install the latest version, restart your Mac and then go on with Homebrew and R.

brew tap homebrew/science
brew install r

This will also install required dependencies like Fortran.

Faster with OpenBLAS

OpenBLAS is library that should speed up calculations in R, but Homebrew does not install it by default. To install R with OpenBLAS bindings you can add the --with-openblas option.

brew install r --with-openblas

This will also install OpenBLAS itself through Homebrew.

Trouble with XQuartz?

I had some trouble with installing R the first time. The reason was an older version of XQuartz. I found the solution on Stackoverflow. A simple brew doctor told me, I was running an outdated XQuartz version.

brew untap homebrew/science
brew tap homebrew/science
brew doctor

After installing the latest version and restarting my Mac, installing R worked fine.

Does it work now?

The quick check for success is starting R with the R command (upper case matters). This should start R and you can type in some R code.

x <- 4 + 5
x

It should print 9 😉.