| Title: | Lightweight Interface to the US Census Bureau API |
|---|---|
| Description: | Download data from the United States Census Bureau API <https://www.census.gov/data/developers/data-sets.html>. The package provides lightweight, product-specific interfaces for ACS, decennial census data, PEP, CBP, migration flows, and time-series datasets. It also uses Census metadata endpoints to discover datasets, variables, tables, and supported geographies, with optional spatial output joined through 'tinytiger'. |
| Authors: | Christopher T. Kenny [aut, cre] (ORCID: <https://orcid.org/0000-0002-9386-6860>) |
| Maintainer: | Christopher T. Kenny <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.0.9000 |
| Built: | 2026-05-09 17:54:46 UTC |
| Source: | https://github.com/christopherkenny/tinycensus |
Retrieve a single Census dataset record
tc_dataset(dataset, year = NULL, refresh = FALSE)tc_dataset(dataset, year = NULL, refresh = FALSE)
dataset |
A Census dataset identifier like |
year |
Optional year. When omitted, the latest available year is used. |
refresh |
Should cached metadata be refreshed? |
A tibble with one row.
tc_dataset("acs/acs5", 2024, refresh = TRUE)tc_dataset("acs/acs5", 2024, refresh = TRUE)
List Census datasets from the discovery catalog
tc_datasets(year = NULL, family = NULL, available = TRUE, refresh = FALSE)tc_datasets(year = NULL, family = NULL, available = TRUE, refresh = FALSE)
year |
Optional year filter. |
family |
Optional dataset family filter, such as |
available |
Should only available datasets be returned? |
refresh |
Should cached metadata be refreshed? |
A tibble of Census API datasets.
tc_datasets(year = 2024, family = "acs", refresh = TRUE)tc_datasets(year = 2024, family = "acs", refresh = TRUE)
Retrieve Census example query metadata
tc_examples(dataset, year = NULL, refresh = FALSE)tc_examples(dataset, year = NULL, refresh = FALSE)
dataset |
A Census dataset identifier like |
year |
Optional dataset year. |
refresh |
Should cached metadata be refreshed? |
A list of example query metadata.
tc_examples("acs/acs5", 2024, refresh = TRUE)tc_examples("acs/acs5", 2024, refresh = TRUE)
Retrieve Census geography metadata
tc_geography(dataset, year = NULL, refresh = FALSE)tc_geography(dataset, year = NULL, refresh = FALSE)
dataset |
A Census dataset identifier like |
year |
Optional dataset year. |
refresh |
Should cached metadata be refreshed? |
A tibble of geography metadata.
tc_geography("acs/acs5", 2024, refresh = TRUE)tc_geography("acs/acs5", 2024, refresh = TRUE)
Retrieve American Community Survey data
tc_get_acs( geography = NULL, variables = NULL, table = NULL, year, survey = c("acs5", "acs1", "acs3"), product = c("detailed", "profile", "subject", "comparison"), within = NULL, predicates = NULL, summary_var = NULL, geometry = FALSE, keep_geo_vars = FALSE, key = tc_get_key(), refresh = FALSE, cache = TRUE, ucgid = NULL, geography_vintage = NULL, ... )tc_get_acs( geography = NULL, variables = NULL, table = NULL, year, survey = c("acs5", "acs1", "acs3"), product = c("detailed", "profile", "subject", "comparison"), within = NULL, predicates = NULL, summary_var = NULL, geometry = FALSE, keep_geo_vars = FALSE, key = tc_get_key(), refresh = FALSE, cache = TRUE, ucgid = NULL, geography_vintage = NULL, ... )
geography |
Census geography name. |
variables |
Optional character vector of variable names. |
table |
Optional ACS table identifier. Mutually exclusive with
|
year |
ACS year. |
survey |
ACS survey, one of |
product |
ACS product, one of |
within |
Optional named list of parent geographies. |
predicates |
Optional named list of additional predicates. |
summary_var |
Optional summary variable to append as
|
geometry |
Should geometry be joined after retrieval? |
keep_geo_vars |
Should source geometry attributes be retained? |
key |
Optional Census API key. |
refresh |
Should cached metadata be refreshed? |
cache |
Should discovery metadata be cached locally? |
ucgid |
Optional |
geography_vintage |
Optional geography vintage used for input normalization. |
... |
Geography values such as |
A tibble or sf object.
tc_get_acs( year = 2024, variables = "B01001_001E", geography = "state", state = c("NY", "Delaware") )tc_get_acs( year = 2024, variables = "B01001_001E", geography = "state", state = c("NY", "Delaware") )
Retrieve County Business Patterns data
tc_get_cbp( geography = NULL, variables = NULL, table = NULL, year, dataset = "cbp", within = NULL, predicates = NULL, summary_var = NULL, geometry = FALSE, keep_geo_vars = FALSE, key = tc_get_key(), refresh = FALSE, cache = TRUE, ucgid = NULL, geography_vintage = NULL, ... )tc_get_cbp( geography = NULL, variables = NULL, table = NULL, year, dataset = "cbp", within = NULL, predicates = NULL, summary_var = NULL, geometry = FALSE, keep_geo_vars = FALSE, key = tc_get_key(), refresh = FALSE, cache = TRUE, ucgid = NULL, geography_vintage = NULL, ... )
geography |
Census geography name. |
variables |
Optional character vector of variable names. |
table |
Optional table or group identifier. Mutually exclusive with
|
year |
Dataset year. |
dataset |
A |
within |
Optional named list of parent geographies. |
predicates |
Optional named list of additional predicates. |
summary_var |
Optional summary variable to append as
|
geometry |
Should geometry be joined after retrieval? |
keep_geo_vars |
Should source geometry attributes be retained? |
key |
Optional Census API key. |
refresh |
Should cached metadata be refreshed? |
cache |
Should discovery metadata be cached locally? |
ucgid |
Optional |
geography_vintage |
Optional geography vintage used for input normalization. |
... |
Geography values such as |
A tibble or sf object.
tc_get_cbp( year = 2021, variables = "ESTAB", geography = "state", state = c("NY", "DE") )tc_get_cbp( year = 2021, variables = "ESTAB", geography = "state", state = c("NY", "DE") )
Retrieve Decennial Census data
tc_get_decennial( geography = NULL, variables = NULL, table = NULL, year, dataset = "pl", within = NULL, predicates = NULL, summary_var = NULL, geometry = FALSE, keep_geo_vars = FALSE, key = tc_get_key(), refresh = FALSE, cache = TRUE, ucgid = NULL, geography_vintage = NULL, ... )tc_get_decennial( geography = NULL, variables = NULL, table = NULL, year, dataset = "pl", within = NULL, predicates = NULL, summary_var = NULL, geometry = FALSE, keep_geo_vars = FALSE, key = tc_get_key(), refresh = FALSE, cache = TRUE, ucgid = NULL, geography_vintage = NULL, ... )
geography |
Census geography name. |
variables |
Optional character vector of variable names. |
table |
Optional table identifier. Mutually exclusive with |
year |
Decennial Census year. |
dataset |
Decennial dataset path, such as |
within |
Optional named list of parent geographies. |
predicates |
Optional named list of additional predicates. |
summary_var |
Optional summary variable to append as
|
geometry |
Should geometry be joined after retrieval? |
keep_geo_vars |
Should source geometry attributes be retained? |
key |
Optional Census API key. |
refresh |
Should cached metadata be refreshed? |
cache |
Should discovery metadata be cached locally? |
ucgid |
Optional |
geography_vintage |
Optional geography vintage used for input normalization. |
... |
Geography values such as |
A tibble or sf object.
tc_get_decennial( year = 2020, dataset = "pl", variables = "P1_001N", geography = "county", state = "Delaware" )tc_get_decennial( year = 2020, dataset = "pl", variables = "P1_001N", geography = "county", state = "Delaware" )
Retrieve ACS migration flows
tc_get_flows( geography, state = NULL, county = NULL, msa = NULL, year = 2018, variables = NULL, breakdown = NULL, breakdown_labels = FALSE, geometry = FALSE, keep_geo_vars = FALSE, key = tc_get_key(), refresh = FALSE )tc_get_flows( geography, state = NULL, county = NULL, msa = NULL, year = 2018, variables = NULL, breakdown = NULL, breakdown_labels = FALSE, geometry = FALSE, keep_geo_vars = FALSE, key = tc_get_key(), refresh = FALSE )
geography |
Flows geography. |
state |
Optional state input. |
county |
Optional county input. |
msa |
Optional metropolitan area codes. |
year |
ACS migration flows year. |
variables |
Optional additional variables. |
breakdown |
Optional breakdown variables. |
breakdown_labels |
Should label columns be added for supported coded breakdown variables? |
geometry |
Should centroid geometry be joined? Use |
keep_geo_vars |
Should source geometry attributes for the selected geometry role be retained? |
key |
Optional Census API key. |
refresh |
Included for consistency with other retrieval helpers. Flows data are requested directly and do not currently use cached metadata. |
A tibble or sf object.
Get the Census API key
tc_get_key()tc_get_key()
A character scalar, or "" if no key is set.
invisible(tc_get_key())invisible(tc_get_key())
Retrieve Census Planning Database data
tc_get_pdb( geography = NULL, variables = NULL, table = NULL, year, dataset = NULL, within = NULL, predicates = NULL, summary_var = NULL, geometry = FALSE, keep_geo_vars = FALSE, key = tc_get_key(), refresh = FALSE, cache = TRUE, ucgid = NULL, geography_vintage = NULL, ... )tc_get_pdb( geography = NULL, variables = NULL, table = NULL, year, dataset = NULL, within = NULL, predicates = NULL, summary_var = NULL, geometry = FALSE, keep_geo_vars = FALSE, key = tc_get_key(), refresh = FALSE, cache = TRUE, ucgid = NULL, geography_vintage = NULL, ... )
geography |
Census geography name. |
variables |
Optional character vector of variable names. |
table |
Optional table or group identifier. Mutually exclusive with
|
year |
Dataset year. |
dataset |
Optional |
within |
Optional named list of parent geographies. |
predicates |
Optional named list of additional predicates. |
summary_var |
Optional summary variable to append as
|
geometry |
Should geometry be joined after retrieval? |
keep_geo_vars |
Should source geometry attributes be retained? |
key |
Optional Census API key. |
refresh |
Should cached metadata be refreshed? |
cache |
Should discovery metadata be cached locally? |
ucgid |
Optional |
geography_vintage |
Optional geography vintage used for input normalization. |
... |
Geography values such as |
A tibble or sf object.
tc_get_pdb( year = 2024, variables = "Tot_Population_CEN_2020", geography = "tract", state = "NY", county = "061" )tc_get_pdb( year = 2024, variables = "Tot_Population_CEN_2020", geography = "tract", state = "NY", county = "061" )
Retrieve Population Estimates Program data
tc_get_pep( geography = NULL, variables = NULL, table = NULL, year, dataset = NULL, product = NULL, breakdown = NULL, within = NULL, predicates = NULL, breakdown_labels = FALSE, summary_var = NULL, geometry = FALSE, keep_geo_vars = FALSE, key = tc_get_key(), refresh = FALSE, cache = TRUE, ucgid = NULL, geography_vintage = NULL, ... )tc_get_pep( geography = NULL, variables = NULL, table = NULL, year, dataset = NULL, product = NULL, breakdown = NULL, within = NULL, predicates = NULL, breakdown_labels = FALSE, summary_var = NULL, geometry = FALSE, keep_geo_vars = FALSE, key = tc_get_key(), refresh = FALSE, cache = TRUE, ucgid = NULL, geography_vintage = NULL, ... )
geography |
Census geography name. |
variables |
Optional character vector of variable names. |
table |
Optional table or group identifier. Mutually exclusive with
|
year |
Dataset year. |
dataset |
PEP dataset path, such as |
product |
Optional PEP product alias. Supported values are
|
breakdown |
Optional characteristics breakdown variables. Supported
values are |
within |
Optional named list of parent geographies. |
predicates |
Optional named list of additional predicates. |
breakdown_labels |
Should label variables for supported breakdowns be added automatically? |
summary_var |
Optional summary variable to append as
|
geometry |
Should geometry be joined after retrieval? |
keep_geo_vars |
Should source geometry attributes be retained? |
key |
Optional Census API key. |
refresh |
Should cached metadata be refreshed? |
cache |
Should discovery metadata be cached locally? |
ucgid |
Optional |
geography_vintage |
Optional geography vintage used for input normalization. |
... |
Geography values such as |
A tibble or sf object.
tc_get_pep( year = 2021, product = "population", geography = "state", state = c("NY", "Delaware") )tc_get_pep( year = 2021, product = "population", geography = "state", state = c("NY", "Delaware") )
Retrieve Census time-series data
tc_get_timeseries( geography = NULL, dataset, variables = NULL, table = NULL, time = NULL, year = NULL, within = NULL, predicates = NULL, key = tc_get_key(), refresh = FALSE, cache = TRUE, ucgid = NULL, ... )tc_get_timeseries( geography = NULL, dataset, variables = NULL, table = NULL, time = NULL, year = NULL, within = NULL, predicates = NULL, key = tc_get_key(), refresh = FALSE, cache = TRUE, ucgid = NULL, ... )
geography |
Optional Census geography name. |
dataset |
A time-series dataset identifier. |
variables |
Optional character vector of variable names. |
table |
Optional group or table identifier. Mutually exclusive with
|
time |
Optional timeseries date value, such as |
year |
Optional dataset year. Most timeseries datasets ignore this and resolve through the discovery catalog. |
within |
Optional named list of parent geographies. |
predicates |
Optional named list of filter predicates other than |
key |
Optional Census API key. |
refresh |
Should cached metadata be refreshed? |
cache |
Should discovery metadata be cached locally? |
ucgid |
Optional |
... |
Geography values such as |
A tibble.
tc_get_timeseries( dataset = "intltrade/exports/hs", variables = "ALL_VAL_MO", time = "2024-01", predicates = list(CTY_CODE = "2010") )tc_get_timeseries( dataset = "intltrade/exports/hs", variables = "ALL_VAL_MO", time = "2024-01", predicates = list(CTY_CODE = "2010") )
Retrieve raw Census group metadata
tc_groups(dataset, year = NULL, refresh = FALSE)tc_groups(dataset, year = NULL, refresh = FALSE)
dataset |
A Census dataset identifier like |
year |
Optional dataset year. |
refresh |
Should cached metadata be refreshed? |
This is a lower-level metadata helper. For most ACS and decennial workflows,
tc_tables() is the more natural entry point because Census "groups" usually
correspond to user-facing tables.
A tibble of group metadata from the Census API.
tc_groups("acs/acs5", 2024, refresh = TRUE)tc_groups("acs/acs5", 2024, refresh = TRUE)
Check for a Census API key
tc_has_key()tc_has_key()
A logical scalar.
tc_has_key()tc_has_key()
Search Census variable metadata
tc_search_variables( dataset, year = NULL, query, fields = c("name", "label", "concept"), ignore_case = TRUE, refresh = FALSE )tc_search_variables( dataset, year = NULL, query, fields = c("name", "label", "concept"), ignore_case = TRUE, refresh = FALSE )
dataset |
A Census dataset identifier like |
year |
Optional dataset year. |
query |
Search string. |
fields |
Metadata fields to search. |
ignore_case |
Should matching ignore case? |
refresh |
Should cached metadata be refreshed? |
A tibble of matching variables.
Adds a Census API key to the current session and, optionally, to a
.Renviron file.
tc_set_key(key, overwrite = FALSE, install = FALSE, r_env = NULL)tc_set_key(key, overwrite = FALSE, install = FALSE, r_env = NULL)
key |
Character scalar API key. |
overwrite |
Should an existing |
install |
Should the key be added to a |
r_env |
Path to the |
Invisibly returns the key.
## Not run: tc_set_key("YOUR-API-KEY") tc_set_key( "YOUR-API-KEY", install = TRUE, overwrite = TRUE, r_env = "~/.Renviron" ) ## End(Not run)## Not run: tc_set_key("YOUR-API-KEY") tc_set_key( "YOUR-API-KEY", install = TRUE, overwrite = TRUE, r_env = "~/.Renviron" ) ## End(Not run)
Retrieve variables for a Census table
tc_table_variables(dataset, table, year = NULL, refresh = FALSE)tc_table_variables(dataset, table, year = NULL, refresh = FALSE)
dataset |
A Census dataset identifier like |
table |
Table or group identifier. |
year |
Optional dataset year. |
refresh |
Should cached metadata be refreshed? |
A tibble of variable metadata for the requested table.
Retrieve Census table metadata
tc_tables(dataset, year = NULL, refresh = FALSE)tc_tables(dataset, year = NULL, refresh = FALSE)
dataset |
A Census dataset identifier like |
year |
Optional dataset year. |
refresh |
Should cached metadata be refreshed? |
This is the preferred helper for exploring ACS and decennial table-level metadata. It wraps the Census API's group metadata in a table-oriented interface.
A tibble of table metadata.
Retrieve encoded values metadata for a Census variable
tc_values(dataset, year = NULL, variable, refresh = FALSE)tc_values(dataset, year = NULL, variable, refresh = FALSE)
dataset |
A Census dataset identifier like |
year |
Optional dataset year. |
variable |
Variable name. |
refresh |
Should cached metadata be refreshed? |
A tibble of value codes and labels.
Retrieve Census variable metadata
tc_variables(dataset, year = NULL, refresh = FALSE)tc_variables(dataset, year = NULL, refresh = FALSE)
dataset |
A Census dataset identifier like |
year |
Optional dataset year. |
refresh |
Should cached metadata be refreshed? |
A tibble of variable metadata.
tc_variables("acs/acs5", 2024, refresh = TRUE)tc_variables("acs/acs5", 2024, refresh = TRUE)