1

I'm trying to analyse data from NARR (NCEP North American Regional Reanalysis) and every time I try my R session crash.

Here is what I do as a reproducible example:

library(raster)

the_NetCDF <- tempfile(fileext = ".nc")

download.file("ftp://ftp.cdc.noaa.gov/Datasets/NARR/Dailies/monolevel/csnow.2019.nc", the_NetCDF)

the_ras <- brick(the_NetCDF)

And here is what I get every time I run the code:

enter image description here

I also tried to open the file in QGIS with also an error.

here is my session info if it can help:

R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252   
[3] LC_MONETARY=English_Canada.1252 LC_NUMERIC=C                   
[5] LC_TIME=English_Canada.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ncdf4_1.17    raster_3.0-12 sp_1.3-2     

loaded via a namespace (and not attached):
[1] compiler_3.6.2   tools_3.6.2      Rcpp_1.0.3       codetools_0.2-16 grid_3.6.2      
[6] lattice_0.20-38 
2
  • 1
    You might be able to workaround by adding mode = "wb" to the download.file call - only matters on Windows (but, it should not crash so I might chase up with raster package)
    – mdsumner
    Commented Feb 18, 2020 at 22:25
  • @mdsumner, yes, it worked! Thanks, you can make it an answer and I'll accept it.
    – Bastien
    Commented Feb 19, 2020 at 3:06

1 Answer 1

1

As @mdsumner specified in its comment, you need to specify the mode of download as binary like:

download.file("ftp://ftp.cdc.noaa.gov/Datasets/NARR/Dailies/monolevel/csnow.2019.nc", the_NetCDF, mode = "wb")

Using this prevent the crash from the raster package.

This is only good on windows, on Linux there was no problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.