get_multi_vintage_data {RcensusPkg} | R Documentation |
get_multi_vintage_data
Description
Get Census Bureau data for a specific dataset, variables, and region
in the form of a data.table
for multiple vintages. The function requires
a Census Bureau access key.
Usage
get_multi_vintage_data(
dataset = NULL,
vintage_v = NULL,
vars = NULL,
region = NULL,
regionin = NULL,
key = Sys.getenv("CENSUS_KEY")
)
Arguments
dataset |
A required string that sets the name of the dataset of interest (e.g. "acs/acs5"). |
vintage_v |
A required numeric vector that sets the vintages of interest. |
vars |
A required string vector of variable acronym names to be acquired (e.g. "B15002_015"). See RcensusPkg::get_variable_names() for obtaining acronym names. |
region |
A string that specifies the geography of the request. See |
regionin |
A string that sets a qualifier for |
key |
A string that sets the access key. All Census Bureau API requests require an access key.
Sign-up for a key is free and can be obtained here.
The function will check for a global setting of the key via |
Value
A data.table
Examples
## Not run:
# Requires Census Bureau API key
# Obtain the median home value (“B25077_001E”) for Deschutes County, Oregon
# back to 2005 through 2019.
library(jsonlite)
library(data.table)
library(httr2)
library(usmap)
library(RcensusPkg)
# Get the fips codes for state and county
deschutes_fips <- usmap::fips("OR","Deschutes")
state <- substr(deschutes_fips,1,2)
county <- substr(deschutes_fips,3,5)
RcensusPkg::get_multi_vintage_data(
dataset = "acs/acs1",
vintage_v = 2005:2019,
vars = c("B25077_001E", "B25077_001M"),
region = paste0("county:", county),
regionin = paste0("state:", state)
)
## End(Not run)