Reads CSV, Excel (.xlsx, .xls), SAS (.sas7bdat), and XPT (.xpt)
files into a tibble. Dispatches on file extension.
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 asreadr::locale(encoding = encoding). Ignored when reading non-CSV formats or when the caller already supplies alocaleargument 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(), orhaven::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
