Skip to content

[Enhancement]: zi_get_geometry() should validate county is a 5-digit GEOID, not silently return zero rows #140

Description

@chris-prener

Parent epic: #109

User story

As a repo maintainer/data consumer of zippeR::zi_get_geometry(), I want a clear, actionable error when county isn't supplied as a valid 5-digit GEOID, so that a malformed request (e.g. passing a county name string) fails loudly instead of silently returning a zero-row result.

Tier: tier/quick-win — low-effort (single input-validation check, matching the existing state/method validation style already in zi_get_geometry()), moderate-impact (prevents a confusing silent-failure UX gap)

Describe the bug

zi_get_geometry()'s county parameter is documented as requiring "a character scalar or vector with character GEOIDs (e.x. "29510")" (see R/zi_get_geometry.R roxygen @param county). If a user instead passes a human-readable county name (e.g. "St. Louis City"), the function does not validate the format and silently proceeds:

zi_get_geometry(year = 2020, state = "MO", county = "St. Louis City", method = "centroid")

Internally, zi_process_county() does counties <- counties[counties$GEOID %in% county, ], which matches zero rows when county isn't a real GEOID, and the function ultimately returns a zero-row sf object with no warning or error — easy to mistake for a package bug (as happened during UAT of #133/PR #138) rather than a usage error.

Expected behavior

zi_get_geometry() should validate that county values are 5-digit numeric-like GEOID strings (mirroring the existing state/method/year argument-checking style already in the function) and cli::cli_abort() with a clear message when they aren't, e.g.:

county must be a 5-digit character GEOID (e.g. "29510"). You provided "St. Louis City".

To Reproduce

zi_get_geometry(year = 2020, state = "MO", county = "St. Louis City", method = "centroid")
#> Simple feature collection with 0 features and 1 field   -- no error, silent zero rows

# correct usage (should be the only accepted form):
zi_get_geometry(year = 2020, state = "MO", county = "29510", method = "centroid")
#> Simple feature collection with 19 features and 1 field  -- works as expected

Desktop (please complete the following information):

  • OS: macOS
  • Version of R: 4.4.1
  • Version of RStudio: N/A

Additional context

Codebase Context

  • R/zi_get_geometry.R: zi_get_geometry() (~line 122) already validates year, style, class, return, shift_geo, and method with explicit cli::cli_abort() checks near the top of the function — county has no equivalent check and should follow the same pattern.
  • R/zi_get_geometry.R: zi_process_county() (~line 435) is where the silent zero-row result actually originates (counties[counties$GEOID %in% county, ]).
  • Related: [Epic H] User-Facing API Ergonomics & Dependency Reduction #109 (Epic H, User-Facing API Ergonomics & Dependency Reduction) — this is exactly the kind of input-validation ergonomics gap that epic tracks.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority/mediumModerate impact, address as capacity allows

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions