I'm trying to open a .nc file with terra, but I'm getting the following error:
'' not recognised as a supported file format. (GDAL error 4)
Reproducible example here (16mb nc file):
if (!file.exists("HadISST_ice.nc")) {
download.file("https://www.metoffice.gov.uk/hadobs/hadisst/data/HadISST_ice.nc.gz","HadISST_ice.nc.gz")
R.utils:::gunzip("HadISST_ice.nc.gz")
}
library(terra)
hadISST <- rast('HadISST_ice.nc')
The file opens with raster::brick, but not with terra:rast, which if I understand correctly from @robert-hijmnan answer is because raster uses ncdf4 while terra uses GDAL.
In GDAL the .nc file opens with no issues via terminal:
% gdalinfo HadISST_ice.nc
Driver: netCDF/Network Common Data Format
Files: HadISST_ice.nc
Size is 512, 512
But I can't read the file with terra without throwing a GDAL error 4. Session info below:
print(sessionInfo())
R version 4.2.0 (2022-04-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.4
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] terra_1.5-34
loaded via a namespace (and not attached):
[1] compiler_4.2.0 tools_4.2.0 Rcpp_1.0.8.3 codetools_0.2-18
and GDAL:
% gdal-config --version
GDAL 3.5.0, released 2022/05/10