read_dua_file {duawranglr} | R Documentation |
Read in raw data file
Description
This function is a wrapper for that will read a variety of file
types. The primary reason to use it rather than base R or tidyverse
functions is that every new file read will reset the
check_pass
environment variable to FALSE
. This is a
security feature in that it requires a new data check each time a
new file is read into memory.
Usage
read_dua_file(file, ...)
Arguments
file |
File name to be read into memory |
... |
Arguments to pass to read function based on the input type; see details for more information. |
Details
The following input types are supported (with the underlying read function and default arguments accompanying):
-
rds:
readRDS()
-
rdata:
load()
-
csv:
readr::read_delim(...,row.names = FALSE, sep = ,)
-
tsv:
read::read_delim(...,row.names = FALSE, sep = '\t')
-
delimited:
readr::read_delim(...,row.names = FALSE)
-
excel:
read_xl::read_excel(...,sheet = 1)
-
stata:
haven::read_dta()
-
sas:
haven::read_sas()
-
spss:
haven::read_sav()
All arguments for these internal write functions, including those
with default values, can be modified by adding them to the
top-level read_dua_file()
function.
Examples
## --------------
## Setup
## --------------
## set DUA crosswalk
dua_cw <- system.file('extdata', 'dua_cw.csv', package = 'duawranglr')
set_dua_cw(dua_cw)
## --------------
## read in data
file <- system.file('extdata', 'admin_data.csv', package = 'duawranglr')
df <- read_dua_file(file)
## show
df
## Not run:
## read in other file types
read_dua_file('admin_data.rds')
read_dua_file('admin_data.txt', sep = '|')
read_dua_file('admin_data.dta')
read_dua_file('admin_data.xlsx', sheet = 2)
## End(Not run)