tests/testthat/test-added-variable.R

test_that("added variable plot requires at least two predictors (audit F10)", {
  expect_error(
    ols_plot_added_variable(lm(mpg ~ disp, data = mtcars), print_plot = FALSE),
    "at least two predictors"
  )

  expect_error(
    ols_plot_added_variable(lm(mpg ~ 1, data = mtcars), print_plot = FALSE),
    "at least two predictors"
  )
})

test_that("added variable plot returns one plot per predictor", {
  p <- ols_plot_added_variable(lm(mpg ~ disp + hp + wt, data = mtcars), print_plot = FALSE)

  expect_length(p, 3)
  expect_s3_class(p[[1]], "ggplot")
})

test_that("ols_prep_avplot_data() gives a clear error for non-model input", {
  expect_error(
    ols_prep_avplot_data(1),
    "`model` must be an object of class `lm`",
    fixed = TRUE
  )
})

Try the olsrr package in your browser

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

olsrr documentation built on Nov. 18, 2026, 5:07 p.m.