mjwoods / RNetCDF

Read and write netcdf format in R
Other
24 stars 9 forks source link

MacOS R studio error: netcdf.h was not compiled - defining CPPFLAGS may help #139

Open Rae-Spr opened 10 months ago

Rae-Spr commented 10 months ago

Hello. I'm running RStudio, version 2022.07.1 554 Build "Spotted Wakerobin" Release for macOS. My computer's MacOS is Monterey Version 12.3.

I am unable to download the RNetCDF package. I keep getting the same error code despite each step I've taken to fix the issue and try the download again (screenshots below). Please note that it is the same outcome whether I use renv::install() or install.packages().

Screen Shot 2024-01-24 at 4 58 19 PM Screen Shot 2024-01-24 at 4 42 15 PM

I have homebrew, so I tried brew install netcdf in terminal.

Screen Shot 2024-01-24 at 5 01 44 PM

I think that worked! No error messages and I can see the download in my homebrew pathway in Finder.

Screen Shot 2024-01-24 at 5 02 41 PM

However, RNetCDF still won't download in my RProject / session. I have tried manually setting the CPPFLAGS and LD_LIBRARY_PATH (using the pathway to the Homebrew folder) in the R terminal.

Screen Shot 2024-01-24 at 4 48 10 PM

I have tried setting these in my Mac's terminal. Same code as above:

export CPPFLAGS="-I/opt/homebrew/Cellar/netcdf/4.9.2_1/include" export LD_LIBRARY_PATH="-I/opt/homebrew/Cellar/netcdf/4.9.2_1/lib":$LD_LIBRARY_PATH

I have tried R CMD install in Terminal. Code below:

R CMD install RNetCDF.tgz --configure-args='CPPFLAGS=-I/opt/homebrew/Cellar/netcdf/4.9.2_1/include LDFLAGS=-I/opt/homebrew/Cellar/netcdf/4.9.2_1/lib'

After every step I've tried, I've attempted a package download in R studio and it has not worked. Same error every time. Any ideas on how to solve this? Thank you in advance!

Rae-Spr commented 10 months ago

I have even tried the direct download in R studio: library(remotes) install_github("https://github.com/mjwoods/RNetCDF.git")

Screen Shot 2024-01-24 at 5 13 51 PM Screen Shot 2024-01-24 at 5 14 05 PM

Same issue, it seems.

mjwoods commented 10 months ago

One thing to check is that the netcdf package from Homebrew may contain a program called nc-config. Can you run that in your Terminal? You may need to add its directory to your PATH environment variable. Once RNetCDF can find that, it should automatically find the other netcdf files that it needs.

If you can't get that to work, you may be able to install RNetCDF from R using the following command (or similar):

install.packages("RNetCDF", configure.args=c("CPPFLAGS=-I/opt/homebrew/Cellar/netcdf/4.9.2_1/include", "LDFLAGS=-L/opt/homebrew/Cellar/netcdf/4.9.2_1/lib")

If that still doesn't work, you could try installing the latest version of R (and optionally RStudio). Then install.packages should find a binary package for RNetCDF, avoiding the need for compilation.