I'm trying to download a bunch of NetCDF files that contain daily data using R. Because I need data for multiple years, I wrote a loop to download the files but I am getting the message that only the first element of 'destfile' argument is used and only the first file is being downloaded.
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")
}
}
}
I've looked at Download multiple files using "download.files" function and the two others hyperlinked within that thread, but I still can't figure out why I'm getting the warning message and how to get R to download multiple files. I'm still somewhat new to R so any help/tips would be great. Thank you!