R 4.0.2 + Mac + issue when installing packages from source

Hello everyone,

I tried to install the latest R version (4.0.2) on my MacBook Pro with macOS Catalina 10.15.5, but I have an issue when installing R packages from source. I didn't have any problem before, when using R (3.6).

For example when I try to install the roxygen2 package with the command install.packages("roxygen2") I get the following error:


  There is a binary version available but the source version is later:
         binary source needs_compilation
roxygen2  7.1.0  7.1.1              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) 
installing the source package ‘roxygen2’

trying URL 'https://cran.rstudio.com/src/contrib/roxygen2_7.1.1.tar.gz'
Content type 'application/x-gzip' length 254118 bytes (248 KB)
==================================================
downloaded 248 KB

* installing *source* package ‘roxygen2’ ...
** package ‘roxygen2’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
/usr/local/clang4/bin/clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include' -I/usr/local/include   -fPIC  -Wall -g -O2  -c RcppExports.cpp -o RcppExports.o
In file included from RcppExports.cpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/Rcpp.h:27:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/RcppCommon.h:29:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/Rcpp/r/headers.h:67:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:100:
In file included from /usr/local/clang4/bin/../include/c++/v1/cmath:305:
/usr/local/clang4/bin/../include/c++/v1/math.h:301:15: fatal error: 'math.h' file not found
#include_next <math.h>
              ^~~~~~~~
1 error generated.
make: *** [RcppExports.o] Error 1
ERROR: compilation failed for package ‘roxygen2’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/roxygen2’
Warning in install.packages :
  installation of package ‘roxygen2’ had non-zero exit status

The downloaded source packages are in
	‘/private/var/folders/3p/0b9xm41j3kvb_885pst3fv580000gn/T/RtmpvHzNsT/downloaded_packages’

Another example is when I try to install the fs package:

  There is a binary version available but the source version is later:
   binary source needs_compilation
fs  1.4.1  1.4.2              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) y
installing the source package ‘fs’

trying URL 'https://cran.rstudio.com/src/contrib/fs_1.4.2.tar.gz'
Content type 'application/x-gzip' length 819583 bytes (800 KB)
==================================================
downloaded 800 KB

* installing *source* package ‘fs’ ...
** package ‘fs’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
/usr/local/clang4/bin/clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I./libuv/include -I. -pthread  -I/usr/local/include   -fPIC  -Wall -g -O2  -c dir.cc -o dir.o
In file included from dir.cc:1:
In file included from ./getmode.h:4:
In file included from /Library/Frameworks/R.framework/Resources/include/Rinternals.h:34:
In file included from /usr/local/clang4/bin/../include/c++/v1/cstdio:100:
/usr/local/clang4/bin/../include/c++/v1/stdio.h:108:15: fatal error: 'stdio.h' file not found
#include_next <stdio.h>
              ^~~~~~~~~
1 error generated.
make: *** [dir.o] Error 1
ERROR: compilation failed for package ‘fs’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/fs’
Warning in install.packages :
  installation of package ‘fs’ had non-zero exit status

The downloaded source packages are in
	‘/private/var/folders/3p/0b9xm41j3kvb_885pst3fv580000gn/T/RtmpvHzNsT/downloaded_packages’

Here are some infos regarding the R session:

R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.0.2 tools_4.0.2

I think that the problem lies in the link between R and clang. I already tried to install and reset the Command Line Toolbox via the Mac Terminal using the commands xcode-select --install and xcode-select --reset, but without success.

Do you know how I can fix this issue?

Thanks in advance,

Alessandro

I had an issue when I upgraded to 4.0 and installing rstan due to a problem with clang. I followed the instructions at this link and it solved my installation problem.

2 Likes

Indeed, problem solved ! Thank you very much !

1 Like

The only thing I just discovered is that R 4.0.0 does not support openMP by default... did you fix that problem too by any chance? Thanks again :wink:

No, sorry. I'm not familiar with openMP

1 Like

There's some discussion at: https://stackoverflow.com/questions/43555410/enable-openmp-support-in-clang-in-mac-os-x-sierra-mojave that is useful. I've managed to compile packages via Homebrew's llvm and libomp. That answer also has a link to a hello world program to test your installation.

1 Like

Thank you! In this case, I guess, you had to modify the ~/.R/Makevars file, right?

You're correct. Here's a version of ~/.R/Makevars I use with llvm and openMP flags set:

LLVM_LOC = /usr/local/opt/llvm
CC=$(LLVM_LOC)/bin/clang -fopenmp
CXX=$(LLVM_LOC)/bin/clang++ -fopenmp
# -O3 should be faster than -O2 (default) level optimisation ..
CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L/usr/local/opt/gettext/lib -L$(LLVM_LOC)/lib -Wl,-rpath,$(LLVM_LOC)/lib
CPPFLAGS=-I/usr/local/opt/gettext/include -I$(LLVM_LOC)/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.