R not recognizing my alternative GCC compiler after config updates?

1.9k views Asked by At

I followed these instructions to get R to use an alternative GCC compiler I have installed on my MacOS.

Building R Packages using Alternate GCC

As basic internet research will tell you (as it told me), the default compiler on the MacOS is clang / clang++, which doesn't work for my specific needs. I installed gcc-8.1 and dependencies in order to enable OpenMP on my machine. OpenMP works when I run gcc-8.1 with a standalone tmp.c file with pragma omp commands in it.

However, when I go back to R to try to run the same code using Rcpp R package, I run into some problems.

The below is what is in my Makevars file located at ~/.R/Makevars on my machine.

PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) $(SHLIB_OPENMP_CFLAGS)
PKG_CFLAGS = $(SHLIB_OPENMP_CFLAGS)
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
CC=gcc-8.1
CXX=g++-8.1
CXX98=g++-8.1
CXX11=g++-8.1
CXX14=g++-8.1
CXX17=g++-8.1

This now correctly activates my alternative complier in lieu of clang++. I can install my package with OpenMP functionality by using a Terminal and using the R commands below.

cd /folder/where/package/is
R CMD build packageName
R CMD build packageName_1.0.tar.gz

However, I cannot install the package using devtools and roxygen2, which I would prefer. Specifically, the devtools function has_devel() fails.

has_devel()
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet CMD SHLIB foo.c 

gcc-8.1 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include  -fopenmp -fPIC  -Wall -g -O2  -c foo.c -o foo.o
/bin/sh: gcc-8.1: command not found
make: *** [foo.o] Error 127
Error: Command failed (1)

Here is the code I use when trying to install updates using devtools / roxygen2.

require(Rcpp)
require(devtools)
require(roxygen2)
setwd("/folder/where/package/is")
compileAttributes(pkgdir = "/folder/where/package/is")
install("packageName/")

I suspect the pop up window I get from RStudio is directly related to has_devel() function failing to be TRUE. If I revert back to using the default compiler, clang++ (by deleting my Makevars at ~/.R/Makevars), has_devel() returns TRUE and RStudio doesn't ask if I want to install developer command line tools. How can I get around this hiccup with installing a package I am developing using devtools instead of installing from source each time?

Proof of Installed Developer Command Line Tools

R build tools error message

0

There are 0 answers