tests/testthat/test-object_has_helpers.R

test_that("object_has_* helpers", {
  expect_true(object_has_names(mtcars, "am"))
  expect_equal(object_has_names(anscombe, c("x1", "z1", "y1")), c(TRUE, FALSE, TRUE))
  expect_equal(object_has_names(list(x = 1, y = 2), c("x", "a")), c(TRUE, FALSE))

  expect_true(object_has_rownames(mtcars))
  expect_false(object_has_rownames(iris))
  expect_false(object_has_rownames(data.frame()))
  expect_error(object_has_rownames(list(x = 1, y = 2)))
})

test_that("object_has_* helpers, additional test", {
  skip_if_not_installed("psych")
  expect_true(object_has_rownames(psych::bfi))
})

Try the insight package in your browser

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

insight documentation built on Nov. 26, 2023, 5:08 p.m.