Hi there!
Since moving to an M1 Macbook Air last year, I've had all sorts of installation problems with R packages. A few months ago I went through some hair pulling, and I think I'm missing some basic information about how all this works.
I'll put more info below, but I'm hoping for your help (1) fixing the problem, and/or (2) finding some resources/readings to help me learn to fish when I have problems like this in the future.
Here's a recent problem--
I tried to install a bioconductor package, but failed to build some of its dependencies from source:
> BiocManager::install("GenomicRanges")
Installing package(s) 'GenomicRanges'
also installing the dependencies ‘zlibbioc’, ‘S4Vectors’, ‘IRanges’, ‘GenomeInfoDb’, ‘XVector’
Packages which are only available in source form, and may need compilation of C/C++/Fortran: ‘zlibbioc’ ‘S4Vectors’ ‘IRanges’ ‘XVector’
‘GenomicRanges’
Do you want to attempt to install these from sources? (Yes/no/cancel)
[...]
* installing *source* package ‘zlibbioc’ ...
** using staged installation
configure: creating ./config.status
config.status: creating src/Makevars
** libs
make: brew: Command not found
make: brew: Command not found
make: brew: Command not found
make: brew: Command not found
mkdir -p "/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/00LOCK-zlibbioc/00new/zlibbioc/include"
/bin/clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/include" -I"/include" -I"/include" -isysroot "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" -Xclang -fopenmp -fPIC -g -O2 -Wall -pedantic -std=gnu99 -mtune=native -pipe -c R_init_zlibbioc.c -o R_init_zlibbioc.o
/bin/sh: /bin/clang: No such file or directory
make: *** [R_init_zlibbioc.o] Error 127
ERROR: compilation failed for package ‘zlibbioc’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/zlibbioc’
I see variations on this general error pattern a lot and have brew installed. A while back to fix a problem like this, I followed a GitHub issue and edited my Makevars to look like this:
julian (-bash) :~$ cat ~/.R/Makevars
XC_LOC:=$(shell xcrun --show-sdk-path)
LLVM_LOC:=$(shell brew --prefix llvm)
GCC_LOC:=$(shell brew --prefix gcc)
GETTEXT_LOC:=$(shell brew --prefix gettext)
OMP_LOC:=$(shell brew --prefix libomp)
CC=$(LLVM_LOC)/bin/clang
CXX=$(LLVM_LOC)/bin/clang++
CXX11=$(LLVM_LOC)/bin/clang++
CXX14=$(LLVM_LOC)/bin/clang++
CXX17=$(LLVM_LOC)/bin/clang++
CXX1X=$(LLVM_LOC)/bin/clang++
CFLAGS=-g -O2 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O2 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L"$(LLVM_LOC)/lib" -L"$(GETTEXT_LOC)/lib" -Wl,-rpath,$(LLVM_LOC)/lib --sysroot="$(XC_LOC)" -lomp
CPPFLAGS=-I"$(GETTEXT_LOC)/include" -I"$(LLVM_LOC)/include" -I"$(OMP_LOC)/include" -isysroot "$(XC_LOC)" -Xclang -fopenmp
FC=$(GCC_LOC)/bin/gfortran
F77=$(GCC_LOC)/bin/gfortran
FLIBS=-L$(GCC_LOC)/lib/gcc/10/ -lm
And for reference:
julian (-bash) :~$ brew --prefix llvm
/opt/homebrew/opt/llvm
julian (-bash) :~$ /opt/homebrew/opt/llvm/bin/clang --help | head -2
OVERVIEW: clang LLVM compiler
And my sessionInfo:
> sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.0.1
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1-arm64/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] BiocManager_1.30.16 compiler_4.1.1 prettyunits_1.1.1 remotes_2.4.2 tools_4.1.1 testthat_3.1.2 digest_0.6.29
[8] pkgbuild_1.3.1 pkgload_1.2.4 evaluate_0.15 memoise_2.0.1 lifecycle_1.0.1 gtable_0.3.0 rlang_1.0.2
[15] cli_3.2.0 rstudioapi_0.13 curl_4.3.2 yaml_2.3.5 xfun_0.30 fastmap_1.1.0 gridExtra_2.3
[22] withr_2.5.0 knitr_1.37 desc_1.4.1 fs_1.5.2 devtools_2.4.3 rprojroot_2.0.2 grid_4.1.1
[29] glue_1.6.2 R6_2.5.1 processx_3.5.2 rmarkdown_2.13 sessioninfo_1.2.2 callr_3.7.0 purrr_0.3.4
[36] magrittr_2.0.2 ps_1.6.0 ellipsis_0.3.2 htmltools_0.5.2 usethis_2.1.5 cachem_1.0.6 crayon_1.5.0