feat(search): basket mode for cog_gov_search() #1

Merged
jared merged 12 commits from feat/cog-gov-search-basket-mode into main 2026-04-28 15:09:44 -04:00
2 changed files with 8 additions and 8 deletions
Showing only changes of commit 68b72faeae - Show all commits
+6 -6
View File
@@ -7,7 +7,7 @@
#' name into one or more `canonical_govid` values before calling #' name into one or more `canonical_govid` values before calling
#' [cog_spending()] / [cog_revenue()] / etc. #' [cog_spending()] / [cog_revenue()] / etc.
#' #'
#' @param pattern Character regex matched case-insensitively against #' @param name Character regex matched case-insensitively against
#' `gov_name`. `NULL` (default) means no name filter. #' `gov_name`. `NULL` (default) means no name filter.
#' @param state Either a 2-letter USPS abbreviation (e.g. `"FL"`), a FIPS #' @param state Either a 2-letter USPS abbreviation (e.g. `"FL"`), a FIPS
#' integer (e.g. `12`), or `NULL`. #' integer (e.g. `12`), or `NULL`.
@@ -18,7 +18,7 @@
#' @return Tibble from `canonical_fips_xwalk` sorted by `population_acs` #' @return Tibble from `canonical_fips_xwalk` sorted by `population_acs`
#' descending (`NULL`s last). #' descending (`NULL`s last).
#' @export #' @export
cog_gov_search <- function(pattern = NULL, state = NULL, type = NULL) { cog_gov_search <- function(name = NULL, state = NULL, type = NULL) {
if (!is.null(type) && .is_excluded_type(type)) { if (!is.null(type) && .is_excluded_type(type)) {
cli::cli_inform(c( cli::cli_inform(c(
i = "v0.1 covers gov_types 0-3 (state/county/city/township) only.", i = "v0.1 covers gov_types 0-3 (state/county/city/township) only.",
@@ -29,13 +29,13 @@ cog_gov_search <- function(pattern = NULL, state = NULL, type = NULL) {
con <- .ensure_session() con <- .ensure_session()
preds <- character(0) preds <- character(0)
if (!is.null(pattern)) { if (!is.null(name)) {
if (!is.character(pattern) || length(pattern) != 1L) { if (!is.character(name) || length(name) != 1L) {
cli::cli_abort("`pattern` must be a length-1 character string.") cli::cli_abort("`name` must be a length-1 character string.")
} }
preds <- c(preds, preds <- c(preds,
sprintf("regexp_matches(gov_name, %s, 'i')", sprintf("regexp_matches(gov_name, %s, 'i')",
.sql_lit_chr(pattern))) .sql_lit_chr(name)))
} }
if (!is.null(state)) { if (!is.null(state)) {
st_fips <- .coerce_state_to_fips(state) st_fips <- .coerce_state_to_fips(state)
+2 -2
View File
@@ -4,10 +4,10 @@
\alias{cog_gov_search} \alias{cog_gov_search}
\title{Search for governments by name, state, and/or type} \title{Search for governments by name, state, and/or type}
\usage{ \usage{
cog_gov_search(pattern = NULL, state = NULL, type = NULL) cog_gov_search(name = NULL, state = NULL, type = NULL)
} }
\arguments{ \arguments{
\item{pattern}{Character regex matched case-insensitively against \item{name}{Character regex matched case-insensitively against
`gov_name`. `NULL` (default) means no name filter.} `gov_name`. `NULL` (default) means no name filter.}
\item{state}{Either a 2-letter USPS abbreviation (e.g. `"FL"`), a FIPS \item{state}{Either a 2-letter USPS abbreviation (e.g. `"FL"`), a FIPS