feat(peers): cog_find_peers uses per-year population

Adds optional 'year' argument (defaults to most recent observed year for
the target). Filters and ranks candidates by gov_population_yearly.population
at that year. Returned column renamed population_acs -> population.
Cohort year attached as attr(x, 'cohort_year').

Adds .resolve_cohort_year() helper. Updates test assertions to use
'population' column name. Regenerates man/cog_find_peers.Rd.
This commit is contained in:
2026-04-29 17:26:32 -04:00
parent 807ed35cb7
commit 54dd40a61d
3 changed files with 80 additions and 40 deletions
+3 -3
View File
@@ -3,7 +3,7 @@ test_that("cog_find_peers returns same-type peers in the default pop band", {
peers <- cog_find_peers("101006006") # Broward County
expect_s3_class(peers, "tbl_df")
expected_cols <- c("canonical_govid", "gov_name", "fips_state",
"population_acs", "pop_ratio", "rank")
"population", "pop_ratio", "rank")
expect_true(all(expected_cols %in% names(peers)))
expect_true(all(peers$pop_ratio >= 0.7 & peers$pop_ratio <= 1.3))
expect_false("101006006" %in% peers$canonical_govid)
@@ -22,8 +22,8 @@ test_that("cog_find_peers absolute pop range works", {
peers <- cog_find_peers("101006006",
pop_range = c(1.5e6, 2.5e6),
is_ratio = FALSE, max_peers = 20L)
expect_true(all(peers$population_acs >= 1.5e6 &
peers$population_acs <= 2.5e6))
expect_true(all(peers$population >= 1.5e6 &
peers$population <= 2.5e6))
})
test_that("cog_find_peers errors cleanly on unknown govid", {