I'm trying to contain my R and associated libraries within individual micromamba environments on my Macbook Air M2. After creating and activating the environment, I install R and some other libraries (gdal, units, geos etc.)
Launching R, I go to install the geospatial package {terra}
with the install.packages('terra')
command.
Following downloading the package from CRAN, I get the following:
* installing *source* package ‘terra’ ...
** package ‘terra’ successfully unpacked and MD5 sums checked
** using staged installation
configure: CC: arm64-apple-darwin20.0.0-clang
configure: CXX: arm64-apple-darwin20.0.0-clang++ -std=gnu++17
checking for gdal-config... /Users/bharris/micromamba/envs/r-spatial/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 3.8.0
checking GDAL version >= 2.0.1... yes
checking for arm64-apple-darwin20.0.0-gcc... arm64-apple-darwin20.0.0-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 the compiler supports GNU C... yes
checking whether arm64-apple-darwin20.0.0-clang accepts -g... yes
checking for arm64-apple-darwin20.0.0-clang option to enable C11 features... none needed
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for gdal.h... yes
checking GDAL: linking with --libs only... yes
checking GDAL: /Users/bharris/micromamba/envs/r-spatial/share/gdal/pcs.csv readable... no
checking GDAL: checking whether PROJ is available for linking:... yes
checking GDAL: checking whether PROJ is available for running:... dyld[35358]: Library not loaded: @rpath/libgdal.34.dylib
Referenced from: <DA07D491-F434-3EA0-A2B6-AA8324B3F9AA> /private/var/folders/_9/52fk_cxx5jqcnbw6539d4ypw0000gq/T/RtmpnEGBi2/R.INSTALL88de25555f02/terra/gdal_proj
Reason: tried: '/usr/local/lib/libgdal.34.dylib' (no such file), '/usr/lib/libgdal.34.dylib' (no such file, not in dyld cache)
./configure: line 3665: 35358 Abort trap: 6 ./gdal_proj
no
configure: error: OGRCoordinateTransformation() does not return a coord.trans: PROJ not available?
ERROR: configuration failed for package ‘terra’
* removing ‘/Users/bharris/micromamba/envs/r-spatial/lib/R/library/terra’
If we run the below:
(r-spatial) bharris@ ~ % find /Users/bharris/micromamba/envs/r-spatial | grep libgdal.34
/Users/bharris/micromamba/envs/r-spatial/lib/libgdal.34.3.8.0.dylib
/Users/bharris/micromamba/envs/r-spatial/lib/libgdal.34.dylib
I can see the location of the mssing libraries. This make sense to a degree -- R is looking for the installed gdal libraries on my default system path rather than the micromamba environment path where they are actually installed. I experienced a similar issue when using homebrew and remedied it by creating a ~/.R/Makevars
file that points to the locations of the homebrew library paths. However, in this case I believe I can't use this approach because creating a single Makevars
file in my home directory might effect all instances of R installed across many different micromamba environments.
In any case, when I did eventually create ~/.R/Makevars
containing the following:
FLIBS=-L/Users/bharris/micromamba/envs/r-spatial/lib
The same error as above persisted. I also tried:
export LD_LIBRARY_PATH=/Users/bharris/micromamba/envs/r-spatial/lib
Before launching R but this resulted in the same error too.
So I have two questions:
- How can I specify R to use a micromamba environment library folder rather than the default system folder and;
- Can whichever method solves 1) also be environment specific?
> sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: aarch64-apple-darwin20.0.0 (64-bit)
Running under: macOS Ventura 13.4
Matrix products: default
BLAS/LAPACK: /Users/bharris/micromamba/envs/r-spatial/lib/libopenblas.0.dylib; LAPACK version 3.11.0
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
time zone: Europe/London
tzcode source: system (macOS)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.3.2 tools_4.3.2