2017-08-10 18:01:09 +02:00
|
|
|
osem_remote_error = function (response) {
|
2017-08-12 15:17:47 +02:00
|
|
|
suppressWarnings({
|
|
|
|
hasCode = !is.null(response$code)
|
|
|
|
})
|
2017-08-10 18:01:09 +02:00
|
|
|
|
2017-08-12 15:17:47 +02:00
|
|
|
if (hasCode) stop(response$message)
|
2017-08-10 18:01:09 +02:00
|
|
|
invisible(response)
|
|
|
|
}
|
|
|
|
|
2017-08-12 15:17:47 +02:00
|
|
|
parse_dateparams = function (from, to) {
|
|
|
|
from = utc_date(from)
|
|
|
|
to = utc_date(to)
|
|
|
|
if (from - to > 0)
|
|
|
|
stop('"from" must be earlier than "to"')
|
|
|
|
|
|
|
|
c(date_as_isostring(from), date_as_isostring(to))
|
|
|
|
}
|
|
|
|
|
|
|
|
# NOTE: cannot handle mixed vectors of POSIXlt and POSIXct
|
|
|
|
utc_date = function (date) {
|
|
|
|
time = as.POSIXct(date)
|
|
|
|
attr(time, 'tzone') = 'UTC'
|
|
|
|
time
|
|
|
|
}
|
|
|
|
|
|
|
|
# NOTE: cannot handle mixed vectors of POSIXlt and POSIXct
|
|
|
|
date_as_isostring = function (date) format(date, format = '%FT%TZ')
|
|
|
|
|
|
|
|
osem_as_sf = function (x, ...) {
|
|
|
|
sf::st_as_sf(x, ..., coords = c('lon', 'lat'), crs = 4326)
|
2017-08-10 18:01:09 +02:00
|
|
|
}
|