tests/testthat/test-test_survey_id.R

test_that("survey_id supports legacy survey objects", {
  s <- survey(
    object = data.frame(x = 1:3),
    id = "survey_1",
    filename = "survey_1.rds"
  )

  expect_identical(survey_id(s), "survey_1")
})

test_that("survey_id supports survey_df objects", {
  s <- survey_df(
    x = data.frame(x = 1:3),
    identifier = "survey_1",
    filename = "survey_1.rds"
  )

  expect_identical(survey_id(s), "survey_1")
})

test_that("Operational survey ID takes precedence", {
  s <- survey_df(
    x = data.frame(x = 1:3),
    identifier = "10.1234/example",
    filename = "survey_1.rds"
  )

  attr(s, "id") <- "survey_1"

  expect_identical(survey_id(s), "survey_1")
})

test_that("survey_id returns NULL when the identifier is absent", {
  s <- survey_df(
    x = data.frame(x = 1:3),
    identifier = "survey_1",
    filename = "survey_1.rds"
  )

  attr(s, "id") <- NULL

  expect_null(survey_id(s))
})

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.