Query data from US Census Bureau API and collect result into dplyr data frame

runCensusAPIQueries(data_url, key, vars, region, numeric = TRUE)

Arguments

data_url

The url root of the api including the '?'

key

API key

vars

A character vector of variable names

region

A region specification containing a 'for:' and possibly an 'in:'

Details

For information on the US Census API see https://www.census.gov/developers/.

This function is a modified version of the code published here: http://rstudio-pubs-static.s3.amazonaws.com/19337_2e7f827190514c569ea136db788ce850.html

See also

Other census functions: queryCensusAPI, statePop, vecToChunk

Examples

# \donttest{ runCensusAPIQueries( data_url = "https://api.census.gov/data/2017/acs/acs5?", key = rstudioapi::askForSecret("censusKey"), vars = paste0("B01001_", str_pad(2:49, 3, pad = "0"), "E"), region = "for=county:*&in=state:31" )
#> Error in str_pad(2:49, 3, pad = "0"): could not find function "str_pad"
# }