read_rpr: Reads Roper Center datasets

Description Usage Arguments Value Examples

View source: R/readroper.R

Description

Reads fixed-width ASCII roper files. Takes arguments in the format a Roper Center survey codebook provides

Usage

1
2
3
4
5
6
7
8
read_rpr(
  col_positions = NaN,
  widths = NaN,
  col_names = NaN,
  filepath = NaN,
  card_read = NaN,
  cards = NaN
)

Arguments

col_positions

starting position(s) to read

widths

width of value(s) to read

col_names

names of columns to return

filepath

data obj or filepath to read

card_read

card to read (if blank, reads a single card dataset)

cards

number of cards in dataset (if null, assumes single card)

Value

a dataframe with len(col_names) number of columns, assigned to the values of col_names

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
fwf_sample <- readroper_example('testMultiCard.txt')
cat(readr::read_lines(fwf_sample))
fwf_sample2 <- readroper_example('testSingleCard.txt')
cat(readr::read_lines(fwf_sample2))
# 1. Fixed width file, first card, multi-card
read_rpr(col_positions=c(1,2,4), widths=c(1,2,1),
col_names=c('V1','V2','V3'), filepath=fwf_sample, card_read=1, cards=2)
# 2 .Fixed width file, first card, single card
read_rpr(col_positions=c(1,2,4), widths=c(1,2,1),
col_names=c('V1','V2','V3'), filepath=fwf_sample2)
 # 3. Fixed width file, second card, multi-card
read_rpr(col_positions=c(1,2,4), widths=c(1,2,1),
col_names=c('V1','V2','V3'), filepath=fwf_sample, card_read=2, cards=2)

readroper documentation built on April 17, 2020, 1:09 a.m.