tests/testthat/test-mar.R

test_that("mar() accepts as input a data.frame only", {
  expect_error(mar(c(1, 2)), "Expected a data.frame object.")
  expect_error(mar(matrix(c(1, 2))), "Expected a data.frame object.")
})

test_that("mar() accepts data with missing values only", {
  expect_error(
    mar(testscores),
    "There is no missing data in this dataset."
  )
})

test_that("mar() warns users of non-numeric encoding", {
  expect_warning(
    mar(animalhealth),
    "Non-numeric columns encoded - verify interpretable."
  )
})

test_that("mar() calculates correct statistics", {
  testthat::skip_on_cran()
  result <- mar(healthcheck)
  expect_equal(result$missing, "rbc")
  expect_equal(result$explanatory, "age")
  expect_equal(
    result$p_values$rbc,
    c(
      0.462530896,
      0.570560304,
      0.325466057,
      0.001876293,
      0.489528756
    )
  )
  expect_equal(
    result$variables$rbc,
    c(
      "bone_mass",
      "body_fat",
      "height",
      "age",
      "rbc"
    )
  )
})

Try the missr package in your browser

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

missr documentation built on June 8, 2025, 12:26 p.m.