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

佐手、 提交于 2020-08-08 05:54:38

问题


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")

回答1:


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')



来源:https://stackoverflow.com/questions/50048989/downloading-netcdf-files-with-r-manually-works-download-file-produces-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!