Search code examples
rgdalr-sfrgdal

Trouble installing package "sf" in R (Big Sur)


I tried to install the sf package because it is a dependency for tidycensus, which is the package I'd like to use. I am using a Mac with Big Sur. Per the Github for r-spatial, I tried following the installation instructions here but no dice. My sessionInfo():

R version 4.1.0 (2021-05-18)
Platform: aarch64-apple-darwin20.4.0 (64-bit)
Running under: macOS Big Sur 11.6

Matrix products: default
BLAS:   /opt/homebrew/Cellar/openblas/0.3.20/lib/libopenblasp-r0.3.20.dylib
LAPACK: /opt/homebrew/Cellar/r/4.1.0/lib/R/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.1.0

I tried

library(devtools)
install_github("r-spatial/sf",configure.args="--with-proj-lib=/opt/homebrew/opt/proj/lib")

The error:

Installing package into ‘/opt/homebrew/lib/R/4.1/site-library’
(as ‘lib’ is unspecified)
* installing *source* package ‘sf’ ...
** using staged installation
configure: CC: /opt/homebrew/opt/llvm/bin/clang
configure: CXX: /opt/homebrew/opt/llvm/bin/clang++ -std=gnu++11
checking for gdal-config... /opt/homebrew/Caskroom/miniforge/base/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 3.4.1
checking GDAL version >= 2.0.1... yes
checking for gcc... /opt/homebrew/opt/llvm/bin/clang
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether /opt/homebrew/opt/llvm/bin/clang accepts -g... yes
checking for /opt/homebrew/opt/llvm/bin/clang option to accept ISO C89... none needed
checking how to run the C preprocessor... /opt/homebrew/opt/llvm/bin/clang -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... rm: conftest.dSYM: is a directory
rm: conftest.dSYM: is a directory
yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking gdal.h usability... yes
checking gdal.h presence... yes
checking for gdal.h... yes
checking GDAL: linking with --libs only... yes
checking GDAL: /opt/homebrew/Caskroom/miniforge/base/share/gdal/pcs.csv readable... no
checking GDAL: checking whether PROJ is available for linking:... yes
checking GDAL: checking whether PROJ is available fur running:... dyld: Library not loaded: @rpath/libgdal.30.dylib
  Referenced from: /private/var/folders/4b/2jtbyjzd1w5gsdm_g_jcpr2h0000gn/T/Rtmp2cQwgC/R.INSTALL5d284632664c/sf/./gdal_proj
  Reason: image not found
./configure: line 3625: 24751 Abort trap: 6           ./gdal_proj
no
configure: error: OGRCoordinateTransformation() does not return a coord.trans: PROJ not available?
ERROR: configuration failed for package ‘sf’
* removing ‘/opt/homebrew/lib/R/4.1/site-library/sf’

Now, something that may be screwing me up (but which I don't know how to fix) is that gdal-config is both in /opt/homebrew/Caskroom/miniforge/base/bin/ and also in /opt/homebrew/opt/gdal/bin/ gdal, proj, and geos all live in /opt/homebrew/opt/


Solution

  • The solution, thanks to @IRTFM, was to download the binary from CRAN, then use R CMD INSTALL. Then I could install tigris and tidycensus via install.packages()