rstudio / renv

renv: Project environments for R.
https://rstudio.github.io/renv/
MIT License
1.02k stars 155 forks source link

Unable to install `RNetCDF` within `renv` on macOS #2009

Closed damonbayer closed 1 month ago

damonbayer commented 1 month ago

I am unable to install RNetCDF within renv on macOS.

I have successfully installed it within renv on Ubuntu. I have also successfully installed it on macOS outside of renv.

Install log:

> renv::install("RNetCDF")
# Downloading packages -------------------------------------------------------
- Downloading RNetCDF from CRAN ...             OK [file is up to date]
Successfully downloaded 1 package in 0.83 seconds.

The following package(s) will be installed:
- RNetCDF [2.9-2]
These packages will be installed into "~/Documents/pyrenew-hew/renv/library/macos/R-4.4/aarch64-apple-darwin20".

Do you want to proceed? [Y/n]: y

# Installing packages --------------------------------------------------------
- Installing RNetCDF ...                        FAILED
Error: Error installing package 'RNetCDF':
===================================

* installing *source* package ‘RNetCDF’ ...
** package ‘RNetCDF’ successfully unpacked and MD5 sums checked
** using staged installation
make: *** No rule to make target `clean'.  Stop.
configure: Find compiler/linker variables from environment:
checking CFLAGS... -I/opt/homebrew/include
checking CPPFLAGS... -I/opt/homebrew/include
checking LDFLAGS... -L/opt/homebrew/lib
checking LIBS... 
configure: Select C compiler:
checking C compiler from --with-mpicc... 
checking C compiler from R... gcc-14
configure: Find compiler/linker variables from R:
checking R_CFLAGS... -I/opt/homebrew/include
checking R_CPPFLAGS... -I/opt/homebrew/include
checking R_LDFLAGS... -L/opt/homebrew/lib
checking for gcc... gcc-14
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 gcc-14 accepts -g... yes
checking for gcc-14 option to enable C11 features... none needed
checking for gcc-14 options needed to detect all undeclared functions... 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 whether _WIN32 is declared... no
checking whether __APPLE__ is declared... yes
configure: Operating system is macOS
checking for nc-config... yes
configure: Check compiler/linker variables from nc-config:
checking NC_CC... clang
checking NC_CC matches selected C compiler... no ... specify --with-mpicc if needed
checking nc-config --cflags... -I/opt/homebrew/Cellar/netcdf/4.9.2_2/include
checking nc-config allows --static option... yes
checking nc-config --libs --static... -L/opt/homebrew/Cellar/netcdf/4.9.2_2/lib -lnetcdf -lhdf5_hl-shared -lhdf5-shared -lm -lz -lzstd -lbz2 -lcurl -lxml2
configure: Check compiler type sizes and language features
checking size of int... 0
checking size of long long... 0
checking size of size_t... 0
checking for C/C++ restrict keyword... __restrict__
configure: Check NetCDF features:
checking for netcdf.h... yes
checking for library containing nc_open... no
configure: error: netcdf library was not linked - defining LDFLAGS may help
ERROR: configuration failed for package ‘RNetCDF’
* removing ‘/Users/damon/Documents/pyrenew-hew/renv/staging/1/RNetCDF’
install of package 'RNetCDF' failed [error code 1]
> 
kevinushey commented 1 month ago

I'm able to reproduce on my macOS machine as well, even though I have netcdf and hdf5 installed from Homebrew.

I note this output:

$ nc-config --libs --static
-L/opt/homebrew/Cellar/netcdf/4.9.2_2/lib -lnetcdf -lhdf5_hl-shared -lhdf5-shared -lm -lz -lzstd -lbz2 -lcurl -lxml2

However, the hdf5 installation from Homebrew doesn't actually provide -lhdf5_hl-shared -lhdf5-shared. I don't know if this would be considered a bug in netcdf or Homebrew, though.

In addition, R only supports installation of CRAN binary packages with the official CRAN builds of R.

damonbayer commented 1 month ago

@kevinushey Are you also able to reproduce "I have also successfully installed it on macOS outside of renv."?

I think you are suggesting the homebrew installations are incomplete, but I must have all the right pieces somehow. They just can't be found when using renv.

kevinushey commented 1 month ago

The package installs successfully with renv for me, as long as I'm using a CRAN build of R:

> renv::install("RNetCDF", rebuild = TRUE)
# Downloading packages -------------------------------------------------------
- Downloading RNetCDF from CRAN ...             OK [file is up to date]
Successfully downloaded 1 package in 0.26 seconds.

The following package(s) will be installed:
- RNetCDF [2.9-2]
These packages will be installed into "~/Library/R/arm64/4.4/library".

Do you want to proceed? [Y/n]:
# Installing packages --------------------------------------------------------
- Installing RNetCDF ...                        OK [installed binary and cached]
Successfully installed 1 package in 0.17 seconds.

You could also try explicitly installing a binary with renv::install("RNetCDF", type = "binary").

damonbayer commented 1 month ago

Can't say I fully followed this conversation or at all understand why this worked, but running renv::install("RNetCDF", rebuild = TRUE) resulted in a successful installation.