So as a disclaimer, I have read multiple threads and tried the different things suggested none of which is working.
This is the code I am using, then I will explain what is happening and what I hope to have happen:
library('rnoaa')
library('dplyr')
library('utils')
library('cgwtools')
data_type <- c('tmax','tmin','PRCP', 'SNOW', 'SNWD')
## Station ID for MSO is GHCND:USW00024153
## Station ID for GPI is GHCND:USC00244558
## Station ID for BTM is GHCND:USW00024135
for (i in 2009:2019){
start_date <- paste(i, '-01-01', sep = "")
end_date <- paste(i, '-12-31', sep = "")
assign(paste('mso_data', i, sep = ""), ncdc(datasetid = 'GHCND', stationid = 'GHCND:USW00024153',
datatypeid = data_type, startdate = start_date,
enddate = end_date, limit = 1000))
a <- paste('mso_data', i, sep = "")
if (i == 1948){
save(a, file = 'mso_data.RData')
}
else {
resave(a, file = 'mso_data.RData')
}
}
mso_data <- ncdc(datasetid = 'GHCND', stationid = 'GHCND:USW00024153',
datatypeid = data_type, startdate = '2020-01-01',
enddate = '2020-07-07', limit = 1000)
resave(mso_data, file = 'mso_data.RData')
Alright, so what I would like to happen is download multiple years of climate data using the package RNOAA. In another post, someone showed me a different way to download this data, in the end, to use their way I still need to fix how I save the data.
RNOAA the function ncdc()
only allows for a maximum 1 year of data to download, so if for instance, you wanted to download 1948 - 2020, I devised the above code. Also, you will see the for loop is (2009:2019) I arbitrarily chose to download 1 decade at a time because the download process is time-intensive. I simply start the for loop at (1948:1959), then (1960:1969), ECT...
I know all the code up to saving works, each individual year of data is visible in my global environment. Where I am having a problem is in the saving. I have tried all of the following extensions ( .RData, .Rda, .rds) which I found in different threads. When I then try to 'read in' that data, it does not exist although I can see it in the destination folder on my computer.
Originally, I was able to save at least my final lines of code that is for the year 2020... all outside the for loop but like I said I am downloading each individual year of data, I have confirmed that.
Thanks