fetchACSReference.RdFetch USA ACS Reference Population On-Demand
fetchACSReference(years, survey = "acs5", census_api_key = NULL)Integer or vector of integers. ACS year(s) (e.g., 2020, or 2021:2023)
Character. Survey type: "acs5" (default) or "acs1"
Character. Census API key. If NULL (default), uses CENSUS_API_KEY environment variable. Warns if neither provided.
StandardizationReference object
Fetches American Community Survey (ACS) estimates from Census API. Requires tidyCensus package and valid Census API key.
Note: ACS provides age-grouped estimates (not single-year). When multiple years are requested, data is combined into a single reference with year column.
if (FALSE) {
# Option 1: Single year with environment variable key
# Sys.setenv(CENSUS_API_KEY = "your_key_here")
acs_2020 <- fetchACSReference(2020)
# Option 2: Single year with direct key parameter
acs_2020 <- fetchACSReference(2020, census_api_key = "your_key_here")
# Option 3: Multiple years (combined into one reference)
acs_2021_2023 <- fetchACSReference(2021:2023, survey = "acs5")
# Use in standardization
result <- standardizePrevalence(
prevalenceData = my_data,
referencePopulation = acs_2020
)
}