Modding R to use BLAS to better support multicore processing, for faster calculations on MacOS

R is an excellent tool for statistical analysis and data wrangling, and its many core and extended functions provide a very useful basis for high-level programming. Unfortunately, its actual calculations tend to be quite a bit slower than they could be (e.g. compared to equivalent calculations in Matlab, Numpy, C++). Part of the reason is simply that current distributions of R default to using slower math libraries that do not take advantage of the fact that most modern machines support multicore processing.

Microsoft R Open (formerly Revolution R Open) provides R distributions that use faster math libraries, allowing much faster processing. They recently stopped supporting MacOS, but most of their performance gains for Mac came from directing R use Mac's own Accelerate math library.

The following allowed me to use the faster BLAS, on Mac OS Mojave on 20190614, so I'm posting it here in case it could be of use to others. It actually makes calculations much faster.

According to the guidance here, after installing the CRAN-compiled R version, one should simply be able to symlink > ln -sf /Library/Frameworks/R.framework/Resources/lib/libRblas.vecLib.dylib /Library/Frameworks/R.framework/Resources/lib/libRblas.dylib to use the Accelerate libraries, and > ln -sf /Library/Frameworks/R.framework/Resources/lib/libRblas.0.dylib /Library/Frameworks/R.framework/Resources/lib/libRblas.dylib to revert to the default BLAS.

The problem is that there isn’t actually a libRblas.vecLib.dylib in the specified folder of the latest version, so you need to dig into the Accelerate library to find it and link it from there instead: > ln -sf /System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Versions/Current/libBLAS.dylib /Library/Frameworks/R.framework/Resources/lib/libRblas.dylib

But then it works fine and can cut the time for some calculations by 85%.