tests/testthat/test-synthetic_population.R

test_that("synthetic_population() works", {

  skip_if(Sys.getenv("CENSUS_API_KEY") == "")
  set.seed(20251229)

  expect_snapshot(
    synthetic_population(
      geography = "state",
      state = "UT",
      year = 2019,
      max_age = 87,
      rate = 10
    )
  )

  # Synthetic population of blocks in mixed GEOIDs
  expect_snapshot(
    synthetic_population(
      geography = "block",
      geoid = c("51001", "40117957200", "490572105041"),
      year = 2000,
      dataset = "decennial"
    )
  )

  # Synthetic population of some random ZCTAs
  expect_snapshot(
    synthetic_population(
      geography = "zcta",
      state = c("CA", "OH", "AL"),
      zcta = c("90210", "44133", "44147", "44136", "01001", "01010"),
      year = 2013,
      dataset = "acs5"
    )
  )

  # Synthetic population
  expect_snapshot(
    synthetic_population(
      geography = "county",
      state = "NY",
      county = c("New York", "Queen", "King", "Bronx", "Richmond"),
      year = 2005,
      dataset = "acs1"
    )
  )
})

Try the sociome package in your browser

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

sociome documentation built on Jan. 10, 2026, 9:17 a.m.