When you extract your variable, you need to specify which dimensions you want. Currently you're asking R to get everything and so I suspect it's creating a 3D array which will likely be enormous.
The ncdf4 package generally supersedes ncdf, you should try using that instead. You need to decide if you want to read data by location for time or by time step for location. This is easier to envisage on a plain 2D grid:
- Single cell at all time steps
- All locations single time step
Yours is a 3D grid through time (albeit with the 3rd dimension only two bands), however it looks like your variable isn't using the bands dimension. Here's a 2D workflow based on ncdf4, ignoring your bands:
Package:
install.packages("ncdf4")
library(ncdf4)
Open connection:
nc = nc_open("~/dir/dir/file.nc")
For a grid at one time step
Read dimensions:
precip = list()
precip$x = ncvar_get(nc, "lon")
precip$y = ncvar_get(nc, "lat")
Read data (note start is the index in dimensions to begin and count is how many observations from that point, so here we read the whole grid at the first time step):
precip$z = ncvar_get(nc, "precip", start=c(1, 1, 1), count=c(-1, -1, 1))
# Convert to a raster if required
precip.r = raster(precip)
To read a single cell at all time steps
You need to find your cell index, precip$x
and precip$y
will help. Once you have it (e.g. cell x=5 and y=10):
precip.cell = ncvar_get(nc, "precip", start=c(5, 10, 1), count=c(1, 1, -1))