Several arguments in ipumsr allow syntax for selecting variables based on dplyr's select function. See details for more information.

Details

There are 3 broad categories of methods for specifying arguments for these select-style parameters.

  • "Character Vector"A character vector of names (such as c("var1", "var2", "var3"))

  • "'Bare' Vector"A vector of 'bare' names (such as c(var1, var2, var3))

  • "Helper Functions"Helper functions from dplyr::select such as starts_with(), contains and others.

Examples

# For microdata, use this syntax to load variables
# Load 3 variables by name
cps_file <- ipums_example("cps_00006.xml")
data <- read_ipums_micro(cps_file, vars = c("YEAR", "MONTH", "PERNUM"))
#> Use of data from IPUMS-CPS is subject to conditions including that users should
#> cite the data appropriately. Use command `ipums_conditions()` for more details.

# Load same 3 variables using bare names
data <- read_ipums_micro(cps_file, vars = c(YEAR, MONTH, PERNUM))
#> Use of data from IPUMS-CPS is subject to conditions including that users should
#> cite the data appropriately. Use command `ipums_conditions()` for more details.

# Use helper functions to load all variables that start with "WT"
data <- read_ipums_micro(cps_file, vars = starts_with("WT"))
#> Use of data from IPUMS-CPS is subject to conditions including that users should
#> cite the data appropriately. Use command `ipums_conditions()` for more details.

# Use bare names and helper function to load YEAR, MONTH and all variables with 'INC' in name
data <- read_ipums_micro(cps_file, vars = c(YEAR, MONTH, contains("INC")))
#> Use of data from IPUMS-CPS is subject to conditions including that users should
#> cite the data appropriately. Use command `ipums_conditions()` for more details.

# For geographic extracts, `data_layer` and `shape_layer` arguments use the same conventions
# to select file names from within zip files.
# (This extract only contains 1 type of file, but some have multiple)
csv_file <- ipums_example("nhgis0008_csv.zip")
data <- read_nhgis(
  csv_file,
  data_layer = contains("pmsa")
)
#> Use of data from NHGIS is subject to conditions including that users should
#> cite the data appropriately. Use command `ipums_conditions()` for more details.
#> 
#> 
#> Reading data file...