FlowWest / CDECRetrieve

An R package to retrieve CDEC data
https://flowwest.github.io/CDECRetrieve/
Other
7 stars 5 forks source link

add error catch for cdec_query start_date and end_date arguments #47

Closed mkoohafkan closed 3 years ago

mkoohafkan commented 6 years ago

Due to this purrr issue (which may be fixed in the next release), using purrr::pmap with cdec_query can cause unexpected results when Date classes are passed to the start_date and/or end_date arguments to cdec_query. purrr:pmap strips the Date class prior to calling the function, which means cdec_query gets integer values for start_date/end_date rather than Date classes. For some reason this doesn't cause an error, it just ignores the start/end specs.

It would be great if cdec_query could have an error catch that makes sure the start_date or end_date arguments are either character or date classes. The simplest solution would probably be to make this change to query_url:

query_url <- glue::glue(cdec_urls$download_shef, STATION = station, SENSOR = as.character(sensor_num), DURCODE = as.character(dur_code), STARTDATE = as.character(as.Date(start_date)), ENDDATE = as.character(as.Date(end_date)))

Which would cause cdec_query to error out when trying to convert an integer to a date without an origin.