feat: cog_balances(), a reader surface for cash and security holdings (#25) #28

Merged
jared merged 22 commits from feat/cog-balances-25 into main 2026-08-03 11:52:13 -04:00
2 changed files with 15 additions and 2 deletions
Showing only changes of commit de3a58d105 - Show all commits
+3 -1
View File
@@ -55,7 +55,7 @@ cog_balances <- function(govid, years, category = NULL,
con <- .ensure_session()
.require_balance_support(con)
.check_govids_in_scope(govid)
scope <- .check_govids_in_scope(govid)
basis_note <- paste0(
"`basis` has no effect on holdings: harmonization_map carries no ",
@@ -77,6 +77,8 @@ cog_balances <- function(govid, years, category = NULL,
expenditure_concept = NA_character_,
revenue_concept = NA_character_
)
prov$scope$govids_found <- scope$found
prov$scope$govids_missing <- scope$missing
attr(result, "provenance") <- prov
result
+12 -1
View File
@@ -144,7 +144,6 @@ test_that("no flow code can reach cog_balances", {
expect_true(length(got) > 0L)
expect_true(all(got %in% balance_codes))
expect_true(length(setdiff(got, balance_codes)) == 0L)
})
})
@@ -166,3 +165,15 @@ test_that("every balance_subtype maps to exactly one category", {
function(x) length(unique(x)))
expect_true(all(per_subtype == 1L))
})
test_that("cog_balances records found + missing govids in provenance", {
skip_if_no_corpus()
with_fixture_corpus({
suppressMessages(
r <- cog_balances(c("550000227544", "XXXINVALID"), 2019)
)
prov <- attr(r, "provenance")
expect_equal(sort(prov$scope$govids_found), "550000227544")
expect_equal(sort(prov$scope$govids_missing), "XXXINVALID")
})
})