tests/testthat/test-tabts-fallback.R

test_that("fixed ARIMAX forecasts without the forecast package", {
  skip_if(
    requireNamespace("forecast", quietly = TRUE),
    "dependency-free fallback is only used when forecast is unavailable"
  )

  set.seed(2026)
  n <- 48L
  d <- data.frame(
    month = seq.Date(as.Date("2020-01-01"), by = "month", length.out = n),
    x = rnorm(n)
  )
  d$y <- 30 + 0.4 * seq_len(n) + 2 * d$x + rnorm(n)

  result <- tabts(
    y,
    time = month,
    data = d,
    model = "arima",
    order = c(1, 0, 0),
    xreg = vars(x),
    forecast = 4,
    future_xreg = tail(d["x"], 4),
    plot = FALSE,
    show = FALSE
  )

  expect_s3_class(result, "r4vn_tabts")
  expect_equal(nrow(result$forecast), 4L)
  expect_true(all(is.finite(result$forecast$Forecast)))
})


test_that("default automatic ARIMA works without forecast", {
  skip_if(
    requireNamespace("forecast", quietly = TRUE),
    "dependency-light automatic fallback is only used when forecast is unavailable"
  )

  set.seed(20260902)
  n <- 60L
  d <- data.frame(
    month = seq.Date(as.Date("2019-01-01"), by = "month", length.out = n),
    y = 40 + 6 * sin(2 * pi * (1:n) / 12) + 0.1 * (1:n) + rnorm(n)
  )

  result <- tabts(
    y,
    time = month,
    data = d,
    forecast = 3,
    plot = FALSE,
    show = FALSE
  )

  expect_s3_class(result, "r4vn_tabts")
  expect_identical(result$model_name, "arima")
  expect_true(isTRUE(attr(result$model, "r4vn_auto_base")))
  expect_equal(nrow(result$forecast), 3L)
  expect_true(all(is.finite(result$forecast$Forecast)))
  expect_match(result$model_info$Details[1], "base R", fixed = TRUE)
})

Try the R4VN package in your browser

Any scripts or data that you put into this service are public.

R4VN documentation built on Sept. 30, 2026, 5:13 p.m.