Receiving odd error while downloading PRISM climate data. How to download a list of dates?

122 Views Asked by At

Trying to get mean temperature for a certain date over the last 5 years. Keep running into this same error. Any suggestions would be greatly appreciated!

get_prism_dailys(type="tmean", dates = as.Date("2018-06-01", "2017-06-01", "2016-06-01", "2015-06-01", "2014-06-01"), keepZip=FALSE)

Error Received:

Error in if (!is_within_daily_range(dates)) stop("Please ensure all dates fall within the valid Prism data record") : missing value where TRUE/FALSE needed

1

There are 1 best solutions below

0
On

The short answer on you question is quite simple: just replace as.Date with the c() function:

get_prism_dailys(type = "tmean", dates = as.Date("2018-06-01", "2017-06-01", 
    "2016-06-01", "2015-06-01", "2014-06-01"), keepZip=FALSE)

It seems to me that the third examples to get_prism_dailys(), which you have probably used, has a small issue. Lets's see on the source code get_prism_dailys(), which is possible with

print(get_prism_dailys)

The dates argument is processed get_prism_dailys() with the gen_dates() function:

dates <- gen_dates(minDate = minDate, maxDate = maxDate, dates = dates)

In its turn, the gen_dates() is transforming the dates argument with as.Dates(), as we can find with getAnywhere():

getAnywhere(gen_dates)
if(!is.null(dates)){    
    # make sure it is cast as a date if it was provided as a character
    dates <- as.Date(dates)

Thus, the transformation of the date input with as.Date() is not necessary, but it is essential to put all the supplied dates into a single vector.

Hope, it will be helpful :)