Learn R Programming

RcensusPkg (version 0.1.5)

get_variable_names: get_variable_names

Description

Get Census Bureau variable acronym names and their label descriptions.

Function produces a data.table of variable acronym names and their descriptions. The function returns 4 columns:

namethe name of the parameter
labelthe Bureau's description of the parameter
requireda boolean indicating if the parameter is required
predicateTypea string indicating the variable primitive type

Note that a variable with a required character value "true" must be included in your data requests (i.e. RcensusPkg::get_vintage_data()) or the API will return an error.

Usage

get_variable_names(
  dataset = NULL,
  category = NULL,
  vintage = 2020,
  vars = NULL,
  group = NULL,
  filter_group_est = FALSE,
  filter_name_str = NULL,
  filter_label_str = NULL,
  filter_concept_str = NULL,
  ignore_case = TRUE,
  fixed = FALSE
)

Value

A data.table

Arguments

dataset

An optional string that sets the name of a dataset category of interest.

category

An optional string that sets the category of datasets. The available categories are one of the following:

acs1American Community Survey 1-Year Data
acs/acsseAmerican Community Survey Supplemental Data
acs5American Community Survey 5-Year Data
decDecennial Census
ecnbasicEconomy-Wide Key Statistics
timeseries/idbTime Series International Database
absAnnual Business Survey

vintage

An required numeric that sets the year of interest. The default is 2020.

vars

An optional vector of variable names whose descriptions are of interest. This parameter requires that either 'dataset' or 'category' had been defined.

group

An optional string that sets the group name associated with a set of variables. This parameter requires that either 'dataset' or 'category' had been defined. See Rcensus::get_groups() for available group names under a specific dataset and vintage.

filter_group_est

A logical which if TRUE will filter the variable names from 'group' and return only estimate related variable names. The default is FALSE.

filter_name_str

A character string by which to filter the resultant data.table's "name" column.

filter_label_str

A character string by which to filter the resultant data.table's "label" column.

filter_concept_str

A character string by which to filter the resultant data.table's "concept" column.

ignore_case

A logical which if FALSE will not ignore case in filtering the "name", "label", "concept" column.

fixed

A logical which if TRUE, then the above filter strings are used 'as is' in matching.

Details

The function's search for variable names depends on either specifying the parameters 'dataset' name or a dataset 'category'. Entering an available 'vintage' also influences obtaining a full dataframe of variable names and descriptions. To assist in using the function the user should consult the Census Bureau's publicly available datasets descriptions. Also of help is Rcensus::get_dataset_names() for available dataset acronym names and their available years.

Examples

Run this code
# Get available variables that have the phrase "educational attainment"
# in "label" column of the resultant data.table.

library(data.table)
library(httr2)
library(RcensusPkg)

educational_attainment_2019_dt <- RcensusPkg::get_variable_names(
  dataset = "acs/acs1/profile",
  vintage = 2019,
  filter_label_str = "educational attainment"
)

Run the code above in your browser using DataLab