Compiling R from source on a Mac
I recently needed to run R devel on a Mac and couldn’t get the precompiled binaries to work (ggplot2 would segfault when I tried to install it – probably a compiler issue). In any case, R is pretty quick to compile from source (at least in terms of wall clock), though there ended up being quite a few Mac-specific issues to tackle.
- Install clang8 or greater, eg here or perhaps with homebrew.
export SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"so clang can find headers that Apple puts in a weird place. Consider adding this to .bash_profile, and potentially .Renviron (I need to logout and back in to test if this is necessary). This was the weirdest and hardest to solve problem.- Download R sources, unpack.
- Edit
config.sitefollowing instructions in the R installation and Administration guide, especially those about setting variablesCC,CXXandR_LD_LIBRARY_PATHto point to where your upgraded version of clang lives. Somehow, after installation, R will magically know to continue to use these compilation variables for all libraries that are installed! - Run
./configuresetting at least--enable-memory-profiling --enable-R-framework --x-libraries=/opt/X11/libif you want to be able to run RStudio against your compiled R. I also set--with-blas="-framework Accelerate", and you could try to set--enable-ltoif you have clang10 (?) or higher for a potential speed-up. make; make installif you set--enable-R-framework. You will probably need sudo formake install, and might need to setSDKROOTagain if you get complaints about missing headers. If you didn’t--enable-R-framework, then considermake install rhome=/usr/local/lib/R-4.0.0-develsince setting rhome to be something non-default will let multiple versions coexist.