我正在尝试使用R下载一堆包含每日数据的NetCDF文件。由于我需要多年的数据,因此我编写了一个循环来下载文件,但是却收到消息,提示“使用destfile'参数,并且仅下载第一个文件。
file_base <- paste0("https://www.ncei.noaa.gov/data/sea-surface-temperature-optimum-interpolation/access/avhrr-only/199801/")
yrs=c("1998")
mon=c("01")
day=("01","02","03")
for (y in yrs){
for (m in mon){
for (d in day){
ymd <- paste0(yrs,mon,day)
fn_url <- paste0 (file_base,"avhrr-only-v2.",ymd,".nc")
fn <- paste0("avhrr-only-v2",ymd,".nc")
download.file(url=paste0(file_base), destfile=fn, method="auto", quiet=TRUE, mode="wb")
}
}
}
我看过Download multiple files using "download.files" function以及该线程中的另两个超链接,但是我仍然不知道为什么收到警告消息以及如何让R下载多个文件。我对R还是有些陌生,所以任何帮助/提示都将很棒。谢谢!
答案 0 :(得分:0)
file_base <- "https://www.ncei.noaa.gov/data/sea-surface-temperature-optimum-interpolation/access/avhrr-only/199801/avhrr-only-v2."
dates <- paste0("199801", sapply(as.character(1:31), function(x) if(nchar(x) == 1) paste0(0, x) else x, simplify = T))
for(date in dates){
download.file(url = paste0(file_base, date, ".nc"),
destfile = paste0("avhrr-only-v2", date, ".nc"),
method = "auto",
quiet = T,
mode = "wb")
}