diff --git a/R/spending.R b/R/spending.R index bb4f641..f662e68 100644 --- a/R/spending.R +++ b/R/spending.R @@ -55,7 +55,7 @@ cog_spending <- function(govid, years, category = NULL, verb = "cog_spending", view_base = "spending_annotated", subtype_col = "spend_subtype", - flow_prefixes = c("E", "F", "G", "K"), + flow_prefixes = c("E", "F", "G"), call = match.call(), govid = govid, years = years, diff --git a/inst/sql/20-spending_long.sql b/inst/sql/20-spending_long.sql index 71eeec2..23c4d82 100644 --- a/inst/sql/20-spending_long.sql +++ b/inst/sql/20-spending_long.sql @@ -1,5 +1,5 @@ CREATE OR REPLACE VIEW spending_long AS SELECT * FROM long -WHERE LEFT(item_code, 1) IN ('E', 'F', 'G', 'K') +WHERE LEFT(item_code, 1) IN ('E', 'F', 'G') AND NOT is_aggregate; diff --git a/inst/sql/22-spending_long_harmonized.sql b/inst/sql/22-spending_long_harmonized.sql index ef70ac8..96baa58 100644 --- a/inst/sql/22-spending_long_harmonized.sql +++ b/inst/sql/22-spending_long_harmonized.sql @@ -3,4 +3,4 @@ SELECT * REPLACE (harmonized_code AS item_code) FROM long WHERE NOT is_aggregate AND harmonized_code IS NOT NULL - AND LEFT(harmonized_code, 1) IN ('E', 'F', 'G', 'K'); + AND LEFT(harmonized_code, 1) IN ('E', 'F', 'G'); diff --git a/tests/testthat/test-expenditure-concept.R b/tests/testthat/test-expenditure-concept.R new file mode 100644 index 0000000..8ae87c0 --- /dev/null +++ b/tests/testthat/test-expenditure-concept.R @@ -0,0 +1,14 @@ +test_that("the corpus contains no K-prefix rows, so the Direct leg omits K", { + con <- .ensure_session() + n <- DBI::dbGetQuery(con, + "SELECT COUNT(*) AS n FROM long WHERE LEFT(item_code, 1) = 'K'")$n + expect_equal(n, 0) + + sql_files <- c("20-spending_long.sql", "22-spending_long_harmonized.sql") + for (f in sql_files) { + txt <- paste(readLines(system.file("sql", f, package = "uscogdata")), + collapse = " ") + expect_false(grepl("'K'", txt, fixed = TRUE), + label = paste(f, "must not reference the inert K prefix")) + } +})