简体   繁体   English

当我使用 R function download.file 从 Internet 下载数据时无法打开 destfile

[英]Cannot open the destfile when I download the data from the internet using the R function download.file

I tried to download the file from the internet, but the downloaded file (raster format) cannot load.我尝试从 Internet 下载文件,但下载的文件(光栅格式)无法加载。

# download the data
download.file("https://zenodo.org/record/4287825/files/ChinaClim_baseline_prec_01.tif?download=1", destfile="prec_01.tif")
# load into Raster
library(raster)
raster("prec_01.tif")
# Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",  : 
# Cannot create a RasterLayer object from this file.

Anything wrong with my code?我的代码有什么问题吗? Thanks.谢谢。

download.file("https://zenodo.org/record/4287825/files/ChinaClim_baseline_prec_01.tif?download=1", destfile="prec_01.tif", mode="wb") # On windows add mode = "wb" to download.file() as suggested by Martin Morgan
# load into Raster
library(raster)
raster("prec_01.tif")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM