Title: | Simply Read ASCII Single and Multicard Polling Datasets |
---|---|
Description: | A convenient way to read fixed-width ASCII polling datasets from providers like the Roper Center <https://ropercenter.cornell.edu>. |
Authors: | Sam Petulla [aut, cre] |
Maintainer: | Sam Petulla <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.9.3 |
Built: | 2025-03-11 03:45:28 UTC |
Source: | https://github.com/petulla/readroper |
Reads fixed-width ASCII roper files. Takes arguments in the format a Roper Center survey codebook provides
read_rpr( col_positions = NaN, widths = NaN, col_names = NaN, filepath = NaN, card_read = NaN, cards = NaN )
read_rpr( col_positions = NaN, widths = NaN, col_names = NaN, filepath = NaN, card_read = NaN, cards = NaN )
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) |
a dataframe with len(col_names)
number of columns, assigned to the values of col_names
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)
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 comes bundled with a number of sample files in its 'inst/extdata' directory. This function make them easy to access
readroper_example(path = NULL)
readroper_example(path = NULL)
path |
Name of file. If 'NULL', the example files will be listed. |
readroper_example() readroper_example('testMultiCard.txt') readroper_example('testSingleCard.txt')
readroper_example() readroper_example('testMultiCard.txt') readroper_example('testSingleCard.txt')