tests/testthat/test-is.labelled_spss.R

# The source code of this helper is in utils.R

test_that("is.labelled_spss recognizes SPSS-labelled vectors", {
  x <- haven::labelled_spss(
    c(1, 2, 99),
    labels = c(yes = 1, no = 2, missing = 99),
    na_values = 99
  )

  expect_true(is.labelled_spss(x))
})


test_that("is.labelled_spss recognizes survey-labelled vectors", {
  x <- labelled_spss_survey(
    x = c(1, 2),
    labels = c(yes = 1, no = 2),
    id = "s1"
  )

  expect_true(is.labelled_spss(x))
})


test_that("is.labelled_spss distinguishes ordinary labelled vectors", {
  x <- haven::labelled(
    c(1, 2),
    labels = c(yes = 1, no = 2)
  )

  expect_false(is.labelled_spss(x))
})


test_that("is.labelled_spss rejects unrelated objects", {
  for (x in list(
    NULL,
    1:3,
    "text",
    factor("yes"),
    data.frame(x = 1)
  )) {
    expect_false(is.labelled_spss(x))
  }
})

Try the retroharmonize package in your browser

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

retroharmonize documentation built on Nov. 29, 2026, 5:06 p.m.