register_model: Register a forecasting model

View source: R/registry.R

register_modelR Documentation

Register a forecasting model

Description

Adds a model to the package's pluggable registry, keyed by key. Every model implements the same three-function contract (fit/forecast/ to_tibble), so once registered it works everywhere in the bundled app (Model tab, Compare Selected Models, Cross-Validation, the Backtest Leaderboard, the Show Code panel) with no other code changes.

Usage

register_model(
  key,
  label,
  fit,
  forecast,
  to_tibble,
  supports_holidays = FALSE,
  requires = NULL,
  annotate = NULL
)

Arguments

key

Character scalar, a unique registry key (e.g. "arima").

label

Character scalar, the human-readable name shown in the UI.

fit

Function with signature fit(train_df, date_agg, ...) returning a fitted model object.

forecast

Function with signature forecast(model_obj, h, ...) returning the model's raw forecast object.

to_tibble

Function with signature to_tibble(raw_forecast_obj, test_df) returning a tibble with columns ds, yhat, and optionally yhat_lower/yhat_upper.

supports_holidays

Logical; whether fit() accepts a holidays_df argument and models holiday effects. Default FALSE.

requires

Character scalar naming an optional package this model needs (e.g. "torch"), or NULL if it has no extra dependency. list_models(available_only = TRUE) omits the model until that package is installed.

annotate

Optional function with signature annotate(model_obj) returning a one-line character description of the fitted model (e.g. "ARIMA(2,1,1)(1,0,0)[12]"), shown as a plot subtitle.

Value

TRUE, invisibly.

Examples

register_model(
  key = "naive_last",
  label = "Naive (last value)",
  fit = function(train_df, date_agg = "day", ...) utils::tail(train_df$y, 1),
  forecast = function(model_obj, h, ...) list(mean = rep(model_obj, h)),
  to_tibble = function(fc_obj, test_df) {
    tibble::tibble(ds = test_df$ds[seq_along(fc_obj$mean)], yhat = fc_obj$mean)
  }
)

forecastsuite documentation built on Oct. 18, 2026, 5:08 p.m.