[GIS] Failed to create a raster-brick from a netCDF file (.nc)

linuxnetcdfr

I am trying to build a raster-brick from a netCDF file (network Common Data Form)

leave this link for more information () but to make a brick (which is part of the package raster) throws me the following error:

Loading required namespace: ncdf4
Failed with error: ‘there is no package called ‘ncdf4’’
Error: requireNamespace("ncdf4") is not TRUE

after that try installing the package ncdf4 but throws the following error when trying to install:

Error, nc-config not found or not executable. This is a script that comes with the
netcdf library, version 4.1-beta2 or later, and must be present for configuration
to succeed.
If you installed the netcdf library (and nc-config) in a standard location, nc-config
should be found automatically. Otherwise, you can specify the full path and name of
the nc-config script by passing the –with-nc-config=/full/path/nc-config argument
flag to the configure script. For example:
./configure –with-nc-config=/sw/dist/netcdf4/bin/nc-config

Special note for R users:

To pass the configure flag to R, use something like this:
R CMD INSTALL –configure-args="–with-nc-config=/home/joe/bin/nc-config" ncdf4
where you should replace /home/joe/bin etc. with the location where you have
installed the nc-config script that came with the netcdf 4 distribution.

How I can resolve this error?

I am new user in Linux, my Linux distro is Linux mint 17.1 and my version of R is 3.2.2

Best Answer

I had the same problem. You should install and the ncdf4 package.

install.packages("ncdf4")

Then be sure to run library(ncdf4) before running the brick function from raster. Below is my code:

library(raster)
library(ncdf4)
r <- brick("E:\\test.nc",varname="precip")
r
Related Question