get_forecasts <- function()

in R_utils/model_eval.R [11:27]


get_forecasts <- function(mable, newdata, ...)
{
    fcast <- forecast(mable, new_data=newdata, ...)
    keyvars <- key_vars(fcast)
    keyvars <- keyvars[-length(keyvars)]
    indexvar <- index_var(fcast)
    fcastvar <- names(fcast)[length(keyvars) + 3]
    fcast <- fcast %>%
        as_tibble() %>%
        pivot_wider(
            id_cols=all_of(c(keyvars, indexvar)),
            names_from=.model,
            values_from=.mean)
    select(newdata, !!keyvars, !!indexvar, !!fcastvar) %>%
        rename(.response=!!fcastvar) %>%
        inner_join(fcast)
}