⏱reading time: 25 min

Update Thursday, 22 of March 2018: I have to add -fopenmp to both clang and clang++ variables in my makevars to be able to build data.table package correctly. This is not exactly what the Data Table wiki recommends. I update the section about the Data Table Package accordingly.

As you know I’m a big fan of Homebrew as a manager of part of the software of my Mac, since it make things easier. There are a lot of guides out there about how to have a R installation 100% Homebrew and some people, like me, like to have this kind of setup because it’s convenient and for the sake of lear a little bit more about how R works in more detail. However, Homebrew setup isn’t officially supported by the R Core Team, so if you find problems with your R installation you aren’t going to get support from them. Nevertheless, you are going to be able to get support from Homebrew and of course, from the regular channels to get help for R, like the mail list.

The biggest advantage, besides of the regular advantages of installing something with HomeBrew, is you can create your own version of R, you can compile it, therefore you can compile it with steroids, so you can take advantage of the OpenBlas and OpenMP libraries.

OpenBLAS & OpenMP

OpenBLAS is a open implementation of the BLAS (Basic Linear Algebra Subprograms) API. Basically, it optimizes your processor when you are doing mathematical operations, like when you are using R. It’s usually a huge leap in performance when you begin to make complex mathematical operations.

OpenMP is a library for Open Multi-Processing, or in other words, be able to use all the cores of your processor when you are compiling C, C++, and Fortran. If also make R to process faster since some packages are able to use all the cores of your computer after you compile them with OpenMP.

In other words, you are going to increase your performance a lot with this setup, as Mauricio Vargas demonstrate in his last two post (Why is R slow? some explanations and MKL/OpenBLAS setup to try to fix this and Is Microsoft R Open faster than CRAN R?).

We also did a small test since we wanted to get this setup in one of our computers, a MacBook Air from 2013. So, we used the MicroBenchmarks package with the below script (from Alexej Gossmann’s Blog) and we got the following results.

We got this results:

On the right the results before we compile R with OpenBLAS and OpenMP using LLVM


Of course there are some problems when you have this kind of install. The first one is the complication of the install process. If it were as simple as install R binaries from CRAN I wouldn’t be doing this guide. The second one and more important, you are going to need to compile the packages you install from now on, without exception. You aren’t going to be able to install the binaries of the packages anymore. This has advantages and disadvantages. The main advantage is that they are going to make use of the libraries you have installed in your your system like OpenBLAS, OpenMP or LLVM, to mention some. However, this means that you are going to need some other libraries to compile and you have to have them correctly linked, like Java or libxml2 or some of the packages aren’t going to compile and you aren’t going to be able to have it on your system.

In case you get any problem internet is your friend. You can look for the error R is returning when it tries to compile. If you are the first one to get that error you can ask in communities like Stackoverflow or the mail list for R help. All of these is going to make you understand R much better and your are going to be a better R user. So take it with patience and consider it like an advance course for R.

Take into account that sometimes even the CRAN install binaries pose problems, mostly with it’s link to Java. Before I decided to have this kind of install with R I had in the past multiple problems with Java and rJava package. So nothing is perfect, but you didn’t decided to use R because it was simple, did you?

How to install?

I’ve used as inspiration for this guide mainly two main sources. On one hand, Bhaskar Karambelar’s installation guide, and on the other Mauricio Vargas’ one. Bhaskar’s one was the first I used, more than 6 months ago, while we were in the United Stated, and really worked well in that moment. Problem with it is, it installs a lot or libraries to program in C/C++ what unless you are a C/C++ programmer you aren’t going to use, although you never know. At that moment, I installed everything due to lack of knowledge, but probably right now I wouldn’t. It’s up to you if you want to install those libraries and programing languages. However, I have more than enough space in my hard drive and I don’t mind to have then, perhaps they are going to to be useful in the future. Besides, this has been a way to discover then and know more about C/C++ programing. Mauricio’s guide goes more to the point and it just helps you to install a really fast and quick version of R that use OpenMP and OpenBlas.

Through this guide I just want to try to show you how I ended with my installation, that is an updated mixture of both guides.  However, take into account that mine guide is going to be a little bit different, even more taking into account that I use Zsh as my shell.


You probably have Homebrew already installed, if you don’t, please, install it. Then, I recommend you to connect to the cask tap if you haven’t done it already:

As you probably you’ve noticed, I don’t tap a lot of repos that Bhaskar taped. This is mainly because those taps are deprecated and its formulae are now included in the Homebrew Core. I decided not to tap other repos because I’m not going to use them.

I recommend to add the following lines in your Zsh and/or Bash profiles running the following:

Uninstalling previous R install

If you already have R installed I recommend you to uninstall R completely. Before you do it, you perhaps want to do a copy of your installed packages, just make a list because you are going to need to compile all of them with this homebrew install. You can run the following code in R to make a copy of your packages.

Now you are going to have a file in your working folder packages.RData that is going to store a variable with a list of all your packages. To reinstall all the packages you just need to load that file in R and run:

Now that you have a list of your installed packages you can delete R from your system. Run the following on terminal:

XCode Command Line Tools

You need to have installed the Command Line Tools for XCode. Please be aware that if you already has installed, XCode you probably still need to install the CLT. The best way to know is running the following command in terminal:

C/C++ Compilers and Libraries

Now, you need to install the C/C++ necessary compilers and other useful libraries.

You can

You can ask fo the versions to check if everything is correctly installed. You have to get something similar to this:

You can check also if the OpenMP from GCC is working running the following on terminal:

And you should get something similar to:

Miscellaneous graphical libraries -optional

Some of these libraries aren’t strictly necessary for R, but they are to install other related apps like QGIS, GRASS or PostGIS. I think that if you don’t want to install then you don’t need to do it right now, since that software install its on dependencies

SSL/SSH Libraries -optional

If you already have Git you probably have OpenSSL, the other two are optional.


It’s highly recomendable to install this library since it’s somehow necessary to install some packages depending on the version of your macOS system. It’s really small (10 mb) so you are losing nothing installing it.

Boost -optional

Boost is one of those libraries that you only install if you program in C/C++. If you want to install it you need to have Libxml2 installed and then proceed as following:

Then you can test if it’s correctly installed

GPG & Git

I’ve already explained how to install GPG in a previous post to use it with Git. How to install Git was also explained.


You are going to probably need X-Server down the road.


Latex is a set of applications and libraries to be able to write beautiful mathematical formulas and documents, mainly. But can be use to write any kind of documents.


If you don’t have Java installed it’s a good moment to do so and to do it with Homebrew.


It’s recommended to install Python 2 and 3 as a complement to R although R itself doesn’t use it.

rply2 is probably to give you an error untill you install R. You can try to install it right now and if it give you the error install again lately.

We are going to install some things before we install R itself. Pandoc is really useful when you have R to convert documents in different formats. Cairo is a graphical library that can be use for in R and it’s need for QGIS. Libsvg and librsvg are optional


Let’s install OpenBLAS, this is one of the key pieces of this installation.

Now you can test if OpenBlas has been correctly installed.

Armadillo and other libraries -optional

Now, you can also install, if you want, Armadillo, which is other library that it’s useful if you program in C/C++ and take advantage of OpenBLAS.

You can test Armadillo with the following code (click to expand, the file is long) since the new Armadillo doesn’t provide examples, or at least I haven’t found them.

You are going to get something like:

You can also test V8


Let’s finally install R.

Then if you are using english (american english) as your main language I recommend you to run the following:


First you have to insert the following line in your Zsh and/or Bash profiles.

And then run the following command in the terminal

You have to get something similar to this:

Folder for R Packages

Let’s create our own folder to store the installed packages for R. This way R, or us, doesn’t have to move all the packages every time we install a new R version. Run the following in terminal.

You should also add this variable to your zsh and/or bash profiles.


LLVM or Low Level Virtual Machine is a library that allow us to compile faster some R packages using OpenMP and also make that those packages use OpenMP when we are normally using R. To install it you run on your terminal the following:

Then insert the LLVM location to your path in your Zsh and/or Bash profiles:

Data Table Package

The package Data Table need a specific makevars file. Makevars file is the file that tells R how and with what libraries it has to compile the packages we download from source. So we are going to install Data Table first, with that specific configuration and then set the final makevars file.

Now we can install Data Table package on terminal. To do so just run on terminal:

Setting the final Makevars

First, we delete the previous makevars file.

Set the final Makevars file.

As you probably have noticed the change is just the -fopenmp flag on the second line. In case you have to reinstall, or update Data Table, you just have to add that flag and then delete it. Really easy and you can even do it from RStudio.


When you install R from Homebrew and you compile it, you don’t have anymore the R shell as an application on your Applications folder. But you can install any other graphical interface like RStudio. To do it you just run in your terminal:

Usually RStudio is able to recognize R install and you don’t need to do anything else.

You can also install some additional related languages like:


From Wikipedia: Node.js is an open-source, cross-platform JavaScript run-time environment for executing JavaScript code server-side. To install it just run:


From Wikipedia: Scala is a general-purpose programming language providing support for functional programming and a strong static type system. To install it just run in your terminal:


From Wikipedia: Go (often referred to as golang) is a programming language created at Google[12] in 2009 by Robert Griesemer, Rob Pike, and Ken Thompson.[10] It is a compiled, statically typed language in the tradition of Algol and C, with garbage collection, limited structural typing,[3]memory safety features and CSP-style concurrent programming features added. To install it just run in your terminal:

You need to modify your zsh and/or bash profile like the following

Some GIS Libraries & Soft -optional

You can also install some GIS libraries. This libraries could be mandatory if you are going to install geographical packages:

Shell Profiles

You’ve been adding things to your Zsh and/or Bash profiles. I recommend you to make those profiles tidy, it’s going to be easier to modify things in the future.

This is how I have then:

You can see those files running the following:

The End

Now you can begin to use your new R.

5 thoughts on “Install R 100% Homebrew Edition With OpenBlas & OpenMP – My Version

  1. Great guide, but is there an advantage to using Openblas over Apple’s Accelerate library? The benchmarks I’ve seen before suggest that they perform about the same. But since the default for Homebrew R is to use Accelerate, this seems like the simpler solution. Would love to hear your thoughts.

    And since I’m here… I had to switch to the binary R installer because Homebrew R wouldn’t work with the R-INLA package. (I get the same error as this guy: https://stackoverflow.com/questions/45494818/r-library-breaks-due-to-failure-in-loading-dyld). This is obviously beyond the scope of your post, but I was wondering if you had any idea on what might be going on there? I’d love to switch back to a 100% Homebrew solution.

    Thanks again for the post, and any other thoughts you might have.

    • About the benchmarking of R homebrew vs R homebrew with openblas (and openmp), well I haven’t seen any specific for both cases. However… I can tell you that R binary from CRAN has that implementation and performed much worse in my wife’s computer than with openBlas from Homebrew (those are the results at the beginning of the post) I can’t tell about just the Homebrew version. I had it for a while and then switched to the openBlas version, but in the change I didn’t perform a benchmark.

      About the other question. I installed that package and seems that everything is OK. I’ve compiled it without problem and loaded also without a warning. Usually those problems are fixed with you install everything again…

      I installed INLA with:

      Because if I try CRAN I get:

      This is suggested in the comment of the question you sent.

  2. Thanks for the reply. Looks like they (recently?) changed the default matrix algebra library for binary R! It used to default to R’s (slow) reference matrix algebra library, which is of course quite slow.

    Regarding INLA, I was able to install it without problems as well, but it throws those errors when you try to run a model. The INLA folks have suggested it’s a problem with Homebrew R, but I can’t imagine why that would be.

    In any case, thanks for taking the time to look into it!

Leave a Reply