macOS Mojave fix for Rcpp compilation headers

C++ headers are currently messed up inside R on Mojave by default.

Note: If you install a macOS system update, you may need to re-run this.

Refer to this comment for additional details.

Example error

For example, say we want to build the data.table and rlang packages from source.

Update old packages: 'data.table', 'rlang'
Update all/some/none? [a/s/n]: a

  There are binary versions available but the source versions are later:
           binary source needs_compilation
data.table 1.12.0 1.12.2              TRUE
rlang       0.3.1  0.3.4              TRUE

If your Rcpp configuration is messed up, you’ll see error messages like this:

In file included from ./data.table.h:1:
/Library/Frameworks/R.framework/Resources/include/R.h:55:11: fatal error: 'stdlib.h' file
      not found
# include <stdlib.h> /* Not used by R itself, but widely assumed in packages */


Setting CPPFLAGS in ~/.R/Makevars doesn’t currently work for Mojave.

CPPFLAGS="-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"

Command line tools

Instead, we have to hard install the headers back to the default location of previous macOS builds. This currently works but isn’t a great solution since it requires modifying the Mojave system.

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

You should see this return in the terminal:

installer: Package name is macOS_SDK_headers_for_macOS_10.14
installer: Installing at base path /
installer: The install was successful.