read_ipums_micro_yield: Read data from an IPUMS extract (in yields)

Description Usage Arguments Details Value Super classes Methods Super classes Methods See Also Examples

View source: R/micro_read_yield.r

Description

Reads a dataset downloaded from the IPUMS extract system, but does so by returning an object that can read a group of lines at a time. This is a more flexible way to read data in chunks than the functions like read_ipums_micro_chunked, allowing you to do things like reading parts of multiple files at the same time and resetting from the beginning more easily than with the chunked functions. Note that while other read_ipums_micro* functions can read from .csv(.gz) or .dat(.gz) files, these functions can only read from .dat(.gz) files.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
read_ipums_micro_yield(
  ddi,
  vars = NULL,
  data_file = NULL,
  verbose = TRUE,
  var_attrs = c("val_labels", "var_label", "var_desc"),
  lower_vars = FALSE
)

read_ipums_micro_list_yield(
  ddi,
  vars = NULL,
  data_file = NULL,
  verbose = TRUE,
  var_attrs = c("val_labels", "var_label", "var_desc"),
  lower_vars = FALSE
)

Arguments

ddi

Either a filepath to a DDI xml file downloaded from the website, or a ipums_ddi object parsed by read_ipums_ddi

vars

Names of variables to load. Accepts a character vector of names, or dplyr_select_style conventions. For hierarchical data, the rectype id variable will be added even if it is not specified.

data_file

Specify a directory to look for the data file. If left empty, it will look in the same directory as the DDI file.

verbose

Logical, indicating whether to print progress information to console.

var_attrs

Variable attributes to add from the DDI, defaults to adding all (val_labels, var_label and var_desc). See set_ipums_var_attributes for more details.

lower_vars

Only if reading a DDI from a file, a logical indicating whether to convert variable names to lowercase (default is FALSE, in line with IPUMS conventions). Note that this argument will be ignored if argument ddi is an ipums_ddi object rather than a file path. See read_ipums_ddi for converting variable names to lowercase when reading in the DDI.

Details

These functions return an IpumsYield R6 object which have the following methods:

Value

A HipYield R6 object (See 'Details' for more information)

Super classes

hipread::HipYield -> hipread::HipLongYield -> IpumsLongYield

Methods

Public methods

Inherited methods

Method new()

Usage
IpumsLongYield$new(
  ddi,
  vars = NULL,
  data_file = NULL,
  verbose = TRUE,
  var_attrs = c("val_labels", "var_label", "var_desc"),
  lower_vars = FALSE
)

Method yield()

Usage
IpumsLongYield$yield(n = 10000)

Super classes

hipread::HipYield -> hipread::HipListYield -> IpumsListYield

Methods

Public methods

Inherited methods

Method new()

Usage
IpumsListYield$new(
  ddi,
  vars = NULL,
  data_file = NULL,
  verbose = TRUE,
  var_attrs = c("val_labels", "var_label", "var_desc"),
  lower_vars = FALSE
)

Method yield()

Usage
IpumsListYield$yield(n = 10000)

See Also

Other ipums_read: read_ipums_micro_chunked(), read_ipums_micro(), read_ipums_sf(), read_nhgis(), read_terra_area(), read_terra_micro(), read_terra_raster()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# An example using "long" data
long_yield <- read_ipums_micro_yield(ipums_example("cps_00006.xml"))
# Get first 10 rows
long_yield$yield(10)
# Get 20 more rows now
long_yield$yield(20)
# See what row we're on now
long_yield$cur_pos
# Reset to beginning
long_yield$reset()
# Read the whole thing in chunks and count Minnesotans
total_mn <- 0
while (!long_yield$is_done()) {
  cur_data <- long_yield$yield(1000)
  total_mn <- total_mn + sum(as_factor(cur_data$STATEFIP) == "Minnesota")
}
total_mn

# Can also read hierarchical data as list:
list_yield <- read_ipums_micro_list_yield(ipums_example("cps_00006.xml"))
list_yield$yield(10)

ipumsr documentation built on July 22, 2020, 1:06 a.m.