feat(peers): stamp cohort_year on cog_peer_compare results

Reads attr(peers, 'cohort_year') when the caller passed a cog_find_peers()
tibble; NA when the caller passed a bare character vector. Stamped as a
constant column on the result and recorded in provenance alongside the
cohort govids.
This commit is contained in:
2026-04-29 17:44:25 -04:00
parent 54dd40a61d
commit a92450ff76
2 changed files with 32 additions and 3 deletions
+20
View File
@@ -111,3 +111,23 @@ test_that("cog_find_peers errors when target has no observed pop in `year`", {
"no observed population"
)
})
test_that("cog_peer_compare stamps cohort_year from peers attribute", {
skip_if_no_corpus()
peers <- cog_find_peers("101006006", year = 2019L, max_peers = 4L)
r <- cog_peer_compare("101006006", peers, "Police", years = 2020L)
expect_true("cohort_year" %in% names(r))
expect_true(all(r$cohort_year == 2019L))
prov <- attr(r, "provenance")
expect_equal(prov$cohort_year, 2019L)
})
test_that("cog_peer_compare cohort_year is NA for bare character peers", {
skip_if_no_corpus()
r <- cog_peer_compare(
"101006006",
peers = c("441015015", "441220220"),
category = "Police", years = 2020L
)
expect_true(all(is.na(r$cohort_year)))
})