0

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

lrthistlethwaite
  • 494
  • 2
  • 6
  • 23
  • 3
    ~/.R should be a directory, ~/.R/Makevars should be a file in that directory. The operating system will allow you to write to that location. – Martin Morgan Sep 15 '18 at 08:48
  • Thanks for your comment. I changed .R to a dir and put the same contents in Makevars file, and I get the same behavior. Any thoughts to my edits? – lrthistlethwaite Sep 16 '18 at 19:55
  • 2
    There are several different C++ flavors -- `CXX`, `CXX98`, `CXX11`, `CXX14`, `CXX17`; likely you need to set the correct one. When debugging, simplify by removing third party tools -- install from the command line with R_HOME/bin/R CMD INSTALL your/package – Martin Morgan Sep 17 '18 at 10:19
  • Your suggestions work! I can now install the package from source via the command line, however, when I load the installed package in an R session, some of the functions are not recognized after I load the library. Not sure why, as I get no build or installation errors. – lrthistlethwaite Oct 08 '18 at 17:49

0 Answers0