Skip to contents

Reads CSV, Excel (.xlsx, .xls), SAS (.sas7bdat), and XPT (.xpt) files into a tibble. Dispatches on file extension.

Usage

read_input(file, sheet = NULL, encoding = NULL, col_select = NULL, ...)

Arguments

file

Path to the data file.

sheet

For Excel files, the sheet name or index to read. Passed to readxl::read_excel(). Ignored for non-Excel formats.

encoding

Character encoding for CSV files (e.g. "UTF-8", "latin1"). Passed as readr::locale(encoding = encoding). Ignored when reading non-CSV formats or when the caller already supplies a locale argument in ....

col_select

Optional character vector of column names to keep. For CSV files the selection is passed directly to readr::read_csv() so excluded columns are never parsed. For other formats columns are subset after reading.

...

Additional arguments passed to the underlying reader (readr::read_csv(), readxl::read_excel(), haven::read_sas(), or haven::read_xpt()).

Value

A tibble::tibble(). SAS/XPT imports preserve haven_labelled vectors as-is.

Examples

path <- tempfile(fileext = ".csv")
readr::write_csv(data.frame(id = 1:3, grp = c("a", "b", "c")), path)
read_input(path)
#> # A tibble: 3 × 2
#>      id grp  
#>   <dbl> <chr>
#> 1     1 a    
#> 2     2 b    
#> 3     3 c