From 9ae46746c0f5a88c743962b4df592c60d478dbd0 Mon Sep 17 00:00:00 2001 From: Jared Knowles Date: Wed, 29 Apr 2026 17:08:56 -0400 Subject: [PATCH] refactor(notes): simplify aggregate-fallback predicate in .notes_column MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The plan-supplied predicate combined three redundant checks (is.null + any + %in% TRUE). Element-wise behavior was correct via scalar recycling, but the form was confusing — a code-quality reviewer misread it as a multi-row false-positive bug. Simplify to mirror the parts[[2]] structure: gate on column presence, then element-wise %in% TRUE check. Equivalent semantics, fewer ways to misread. --- R/spending.R | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/R/spending.R b/R/spending.R index 8830fe9..5e0c7eb 100644 --- a/R/spending.R +++ b/R/spending.R @@ -189,11 +189,13 @@ cog_spending <- function(govid, years, category = NULL, if (n == 0L) return(character(0)) parts <- vector("list", 2L) agg <- result[["aggregate_fallback"]] - parts[[1]] <- ifelse( - !is.null(agg) & isTRUE(any(agg, na.rm = TRUE)) & agg %in% TRUE, - "Aggregate fallback applied; see cog_explain()", - NA_character_ - ) + parts[[1]] <- if (!is.null(agg)) { + ifelse(agg %in% TRUE, + "Aggregate fallback applied; see cog_explain()", + NA_character_) + } else { + rep(NA_character_, n) + } ps <- result[["pop_source"]] parts[[2]] <- if (!is.null(ps)) { ifelse(ps == "unavailable",