get_geoids: Obtain GEOIDs of areas

View source: R/get_geoids.R

get_geoidsR Documentation

Obtain GEOIDs of areas

Description

Returns a tibble or sf of GEOIDs, names, and decennial census population of user-specified locations.

Usage

get_geoids(
  geography = c("state", "county", "tract", "block group", "block", "zcta",
    "zip code tabulation area"),
  state = NULL,
  county = NULL,
  geoid = NULL,
  zcta = NULL,
  year,
  dataset = c("acs5", "decennial", "acs3", "acs1"),
  geometry = FALSE,
  cache_tables = TRUE,
  key = NULL,
  evaluator = purrr::insistently(eval, rate = purrr::rate_delay(), quiet = FALSE),
  ...
)

Arguments

geography

A character string denoting the level of census geography whose GEOIDs you'd like to obtain. Must be one of c("state", "county", "tract", "block group", "block", "zcta") ("zip code tabulation area" will be automatically changed to "zcta").

state

A character string specifying states whose ADI and ADI-3 data is desired. Defaults to NULL. Can contain full state names, two-letter state abbreviations, or a two-digit FIPS code/GEOID (must be a vector of strings, so use quotation marks and leading zeros if necessary). Must be left as NULL if using the geoid.

If geography = "zcta" and year is earlier than 2020, this argument can be used to only include ZCTAs associated with specific states, as determined by the US Census bureau. If year is 2020 or later, this argument will be ignored with a warning.

county

A vector of character strings specifying the counties whose ADI and ADI-3 data you're requesting. Defaults to NULL. If not NULL, the state parameter must have a length of 1. County names and three-digit FIPS codes are accepted (must contain strings, so use quotation marks and leading zeros if necessary). Must be NULL if using the geoid parameter or if geography = "zcta".

geoid

A character vector of GEOIDs (use quotation marks and leading zeros). Defaults to NULL. Must be blank if state, county, or zcta is used. Can contain different levels of geography (see details).

zcta

A character vector of ZCTAs or the leading digit(s) of ZCTAs (use quotation marks and leading zeros). Defaults to NULL. Must be blank if county or geoid is used.

Strings under 5 digits long will yield all ZCTAs that begin with those digits.

Requires that geography = "zcta". If geography = "zcta" and zcta = NULL, all ZCTAs in the 50 states plus DC and Puerto Rico will be used.

year

Single integer specifying the year of US Census data to use.

dataset

The data set used to calculate ADIs and ADI-3s. Must be one of c("acs5", "acs3", "acs1", "decennial"), denoting the 5-, 3-, and 1-year ACS along with the decennial census. Defaults to "acs5".

When dataset = "decennial", year must be in c(2000, 2010, 2020).

The 2010 and 2020 decennial censuses did not include the long-form questionnaire used in the 1990 and 2000 censuses, so this function uses the 5-year estimates from the 2010/2020 ACS to supply the data not included in the decennial censuses.

Important: data are not always available depending on the level of geography and data set chosen. See dataset_year_geography_availability and https://www.census.gov/programs-surveys/acs/guidance/estimates.html.

geometry

Logical value indicating whether or not shapefile data should be included in the result, making the result an sf object instead of a plain tibble. Defaults to FALSE.

The shapefile data that is returned is somewhat customizable by passing certain arguments along to the tidycensus functions via ....

cache_tables

The plural version of the cache_table argument in tidycensus::get_acs() or tidycensus::get_decennial(). (get_adi() calls the necessary tidycensus function many times in order to return ADIs and ADI-3s, so many tables are cached if TRUE). Defaults to TRUE.

key

Your Census API key as a character string. Obtain one at http://api.census.gov/data/key_signup.html. Defaults to NULL. Not necessary if you have already loaded your key with census_api_key().

evaluator

A function that will evaluate the calls to the tidycensus functions. Defaults to purrr::insistently(eval⁠, rate = ⁠purrr::rate_delay()⁠, quiet = FALSE)⁠.

...

Additional arguments to be passed to tidycensus::get_decennial(). Use at your own risk.

Details

This allows users to quickly obtain all GEOIDs in a specified location at a specific level of geography without having to manually look them up somewhere else.

This facilitates calls to get_adi() that involve somewhat complicated reference areas.

See Also

dataset_year_geography_availability for usable combinations of dataset, year, and geography.

Examples

## Not run: 
# Wrapped in \dontrun{} because it requires a Census API key.

# Get all tract GEOIDs for Manhattan
tracts <- get_geoids(geography = "tract", state = "New York", county = "New York")
tracts

# Get all block GEOIDs for the fifth tract on that list
get_geoids(geography = "block", geoid = tracts$GEOID[5])

## End(Not run)

sociome documentation built on Jan. 10, 2026, 9:17 a.m.

Related to get_geoids in sociome...