Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading NetCDF files with R: Manually works, download.file produces error

I am trying to download a set of NetCDF files from: ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/nwm/prod/nwm.20180425/medium_range/

When I manually download the files I have no issues connecting, but when I use download.file and attempt to connect I get the following error: Assertion failed!

Program: C:\Program Files\Rstudio\bin\rsession.exe File: nc4file.c, Line 2771

Expression: 0

This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.

I have attempted to run the code in R without R studio and got the same result.

My abbreviated code is as followed:

library("ncdf4")
library("ncdf4.helpers")
download.file("ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/nwm/prod/nwm.20180425/medium_range/nwm.t00z.medium_range.channel_rt.f006.conus.nc","c:/users/nt/desktop/nwm.t00z.medium_range.channel_rt.f006.conus.nc")
temp = nc_open("c:/users/nt/desktop/nwm.t00z.medium_range.channel_rt.f006.conus.nc")
like image 923
nick Avatar asked Jan 02 '23 11:01

nick


1 Answers

Adding mode = 'wb' to the download.file arguments solves the issue for me. I've had the same problem when downloading PDFs

download.file("ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/nwm/prod/nwm.20180425/medium_range/nwm.t00z.medium_range.channel_rt.f006.conus.nc","C:/teste/teste.nc", mode = 'wb')

like image 177
Luis Avatar answered Apr 07 '23 10:04

Luis