Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to install R packages "RNetCDF" and "ncdf" on Ubuntu?

I would like to use the R packages RNetCDF and ncdf in Ubuntu.

When I try install.packages('RNetCDF') or install.packages('ncdf'), I get similar errors:

...
ncdf.c:3:20: fatal error: netcdf.h: No such file or directory
compilation terminated.
make: *** [ncdf.o] Error 1
ERROR: compilation failed for package ‘ncdf’
...
Warning message:
In install.packages("ncdf") :
  installation of package ‘ncdf’ had non-zero exit status

The packages libnetcdf6 and netcdf-bin from the Ubuntu repository are installed. Do I need to do something else?

like image 619
Abe Avatar asked Jul 03 '12 21:07

Abe


3 Answers

In my case, libudunits2-dev package was needed.

sudo apt-get install libudunits2-dev

Since I installed NetCDF from source, I had to manually specify the locations of lib and include folders

install.packages("/home/user/Downloads/RNetCDF_1.6.1-2.tar.gz", 
repos = NULL,
type="source",
dependencies=FALSE,
configure.args="--with-netcdf-include=/usr/local/netcdf-4.2.1-build/include --with-netcdf-lib=/usr/local/netcdf-4.2.1-build/lib")
like image 195
Sadiq Huq Avatar answered Nov 19 '22 21:11

Sadiq Huq


You need to install the -dev of those packages to get the headers that are required to compile the package. In this case, you need libnetcdf-dev, udunits-bin and libudunits2-dev

like image 14
Justin Avatar answered Nov 19 '22 19:11

Justin


Just to clarify, since your initial issue is in R, and the fix is applied outside of R. I initially was trying to do

install.packages("libnetcdf-dev"), which didn't work.

instead, from outside of R: sudo apt-get install libnetcdf-dev

That fixed it for me.

like image 1
AtomicTech Avatar answered Nov 19 '22 21:11

AtomicTech