Checks that American Community Survey (ACS) estimates for census tracts,
such as a table from tidycensus::get_acs() with geometry = TRUE, have
the form that cacs_intersect_weight() and the acs argument of
cacs_run() require. cacs_run() checks at the start only that acs is
an sf object, and makes the other checks at its intersection step,
after the routing step.
Value
TRUE, invisibly, when every check passes. Otherwise the function
stops with an error of class catchmentACS_error_schema at the first
check that fails.
Details
The checks are made in this order, and the first one that fails stops the function with an error:
xis ansfobject.Its coordinate reference system is NAD83 (EPSG:4269).
It has the columns
GEOID,NAME,variable,estimate,moe(the margin of error), andgeometry.It has at least one row.
Every
GEOIDhas 11 digits, like a census tract code.estimateandmoeare numeric.No tract has two rows for the same variable.
Whether variable holds ACS codes, and the values of estimate and
moe, are not checked. A name in place of an ACS code, such as "pop"
from tidycensus::get_acs(variables = c(pop = "B01003_001")), gets NA
values, and cacs_run() then stops with an error about ACS codes that are
not combined. Census Bureau annotation codes, such as -555555555, pass
the checks. cacs_intersect_weight() treats them as missing, and its
warning counts them, except a margin-of-error code next to a missing
estimate; the example data below have only such codes and give no
warning. A tract with no row for one of the variables is not reported,
and it is left out of that variable's total or average without a warning.
Whether every tract has one row for each variable can be checked with
all(table(acs$GEOID, acs$variable) == 1).
See also
cacs_acs_prefetch() downloads ACS data in this form.
Other validation and conditions:
cacs_capture_conditions(),
cacs_validate_iso(),
cacs_validate_osrm_endpoint(),
catchmentACS-conditions
Examples
acs <- readRDS(system.file("extdata", "sample_alabama_subset.rds",
package = "catchmentACS"))
cacs_acs_validate(acs)
# tidycensus downloads the data, which needs a Census API key.
if (FALSE) { # \dontrun{
my_acs <- tidycensus::get_acs(
geography = "tract", variables = "B01003_001",
state = "AL", year = 2023, geometry = TRUE, output = "tidy"
)
cacs_acs_validate(my_acs)
} # }