validate_forecast()
validates a forecast by checking that:
it is a named list
it contains a valid data frame
its forecast time is compatible with its time type If any of these conditions fail, it stops with an appropriate an error message
Examples
# valid forecast
casteval:::validate_forecast(list(
name="hello",
forecast_time=5,
data=data.frame(time=1:3, val=4:6)
))
# not a forecast
try(casteval:::validate_forecast(data.frame(time=1:3, val=4:6)))
#> Error in casteval:::validate_forecast(data.frame(time = 1:3, val = 4:6)) :
#> forecast must be named list containing data frame, not just a data frame
# bad forecast_time type
try(casteval:::validate_forecast(list(
forecast_time=lubridate::as_date(1000),
data=data.frame(time=1:3, val=4:6)
)))
#> Error in validate_time(fcst$forecast_time, fcst) :
#> type of `t` does not match `fcst$time_type`