tests/testthat/test-crosswalk-original-codes.R

test_that("Crosswalk rejects contradictory original value codes", {
  x <- labelled_spss_survey(
    x = c(1, 2, 1),
    labels = c(Yes = 2, No = 1),
    id = "survey_1",
    name_orig = "q1"
  )

  s <- survey_df(
    x = tibble::tibble(
      rowid = paste0("survey_1_", seq_along(x)),
      q1 = x
    ),
    identifier = "survey_1",
    filename = "survey_1.rds"
  )

  cw <- data.frame(
    id = "survey_1",
    var_name_orig = "q1",
    var_name_target = "q1",
    val_label_orig = c("Yes", "No"),
    val_label_target = c("agree", "disagree"),
    val_numeric_orig = c(1, 2),
    val_numeric_target = c(10, 20)
  )

  expect_error(
    crosswalk_surveys(
      crosswalk_table = cw,
      survey_list = list(s)
    ),
    regexp = "Original value codes do not match source labels"
  )
})

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.