feat: cog_gov_search + cog_mirror + scope-aware verb behavior
Three pieces:
1. cog_gov_search: name/state/type search over canonical_fips_xwalk
for resolving human-readable place names into canonical_govids.
Accepts USPS abbrev ('FL') or FIPS int (12) for state; integer
0-3 or name ('state','county','city','township') for type. Types
4/5 emit an explanatory cli message and return an empty tibble
(v0.1 corpus excludes them). USPS<->FIPS table hardcoded with
50 states + DC + territories; FIPS 66 = GU (not GA).
2. cog_mirror: downloads manifest-listed files to a local directory
with SHA-256 idempotency (files with matching hash return status
'cached'). Supports HTTP and local-path fixture URLs. Round-trip
test: mirror + re-open against the mirror + query Broward 2020
returns identical results.
3. Scope-aware verbs: .check_govids_in_scope() helper in session.R
queries canonical_fips_xwalk for the requested govids, emits a
cli_inform listing any missing ones, and records the found/missing
sets under provenance$scope. Wired into cog_spending (and
transitively into cog_revenue, cog_geographic_rollup,
cog_peer_compare via their cog_spending calls).
Also: dropped dbplyr from Imports (unused).
Tests: +29 (22 search + 12 mirror - 5 refactored) / 159 total pass.
devtools::check() now clean: 0E / 0W / 0N.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/search.R
|
||||
\name{cog_gov_search}
|
||||
\alias{cog_gov_search}
|
||||
\title{Search for governments by name, state, and/or type}
|
||||
\usage{
|
||||
cog_gov_search(pattern = NULL, state = NULL, type = NULL)
|
||||
}
|
||||
\arguments{
|
||||
\item{pattern}{Character regex matched case-insensitively against
|
||||
`gov_name`. `NULL` (default) means no name filter.}
|
||||
|
||||
\item{state}{Either a 2-letter USPS abbreviation (e.g. `"FL"`), a FIPS
|
||||
integer (e.g. `12`), or `NULL`.}
|
||||
|
||||
\item{type}{Government type: an integer in `0:3` or one of `"state"`,
|
||||
`"county"`, `"city"`, `"township"`. Passing `4`, `5`,
|
||||
`"special_district"`, or `"school_district"` emits an explanatory
|
||||
message and returns an empty tibble (v0.1 corpus excludes those types).}
|
||||
}
|
||||
\value{
|
||||
Tibble from `canonical_fips_xwalk` sorted by `population_acs`
|
||||
descending (`NULL`s last).
|
||||
}
|
||||
\description{
|
||||
Returns rows from `canonical_fips_xwalk` matching the supplied filters.
|
||||
Intended as the entry point users call to resolve a human-readable place
|
||||
name into one or more `canonical_govid` values before calling
|
||||
[cog_spending()] / [cog_revenue()] / etc.
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/mirror.R
|
||||
\name{cog_mirror}
|
||||
\alias{cog_mirror}
|
||||
\title{Mirror the published corpus to a local directory}
|
||||
\usage{
|
||||
cog_mirror(
|
||||
dest,
|
||||
include = c("long", "metadata", "docs"),
|
||||
overwrite = FALSE,
|
||||
progress = interactive()
|
||||
)
|
||||
}
|
||||
\arguments{
|
||||
\item{dest}{Destination directory. Created if missing.}
|
||||
|
||||
\item{include}{Subset of `c("long", "metadata", "docs")` controlling
|
||||
which manifest sections to mirror.}
|
||||
|
||||
\item{overwrite}{If `TRUE`, re-copy even when the local SHA matches.}
|
||||
|
||||
\item{progress}{If `TRUE`, show a cli progress bar.}
|
||||
}
|
||||
\value{
|
||||
Invisibly, a tibble of `(path, sha256, size_bytes, status)`
|
||||
rows where `status` is `"downloaded"` or `"cached"`.
|
||||
}
|
||||
\description{
|
||||
Downloads (or copies, for local-path fixture URLs) every file listed in
|
||||
the session's `manifest.json` into `dest`, preserving the relative path
|
||||
structure. Files already present with a matching SHA-256 hash are
|
||||
skipped unless `overwrite = TRUE`. The resulting directory can be
|
||||
pointed at via `options(uscogdata.url = paste0(dest, "/"))` for offline
|
||||
analysis.
|
||||
}
|
||||
Reference in New Issue
Block a user