tests/testthat/test-survey-country-population.R

test_that("survey_country_population() works", {
  expect_snapshot(
    as.data.frame(survey_country_population(polymod))
  )
  expect_snapshot(
    as.data.frame(survey_country_population(polymod, countries = "Belgium"))
  )
  expect_snapshot(
    as.data.frame(survey_country_population(
      polymod,
      countries = c("Belgium", "Italy")
    ))
  )
  expect_snapshot(
    as.data.frame(survey_country_population(polymod, countries = "Australia"))
  )
})

test_that("survey_country_population() errors appropriately", {
  # When no country information provided
  polymod_copy <- polymod
  polymod_copy$participants$country <- NULL
  expect_snapshot(
    error = TRUE,
    survey_country_population(polymod_copy)
  )
})

Try the socialmixr package in your browser

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

socialmixr documentation built on April 29, 2026, 9:07 a.m.