smart_read | R Documentation |
A simple function that imports a file without the users needing to
specify information about the file type (see Details for more).
The smart_read()
function uses the file's extension to determine
the appropriate function to read the data.
Additionally, characters are converted to factors by default,
mostly for compatibility with iNZight (https://inzight.nz).
smart_read(
file,
ext = tools::file_ext(file),
preview = FALSE,
column_types = NULL,
...
)
file |
the file path to read |
ext |
file extension, namely "csv" or "txt" |
preview |
logical, if |
column_types |
vector of column types (see ?readr::read_csv) |
... |
additional parameters passed to read_* functions |
Currently, smart_read()
understands the following file types:
delimited (.csv, .txt)
Excel (.xls, .xlsx)
SPSS (.sav)
Stata (.dta)
SAS (.sas7bdat, .xpt)
R data (.rds)
JSON (.json)
A dataframe with some additional attributes:
name
is the name of the file
code
contains the 'tidyverse' code used to read the data
sheets
contains names of sheets if 'file' is an Excel file (can be retrieved using the sheets()
helper function)
By default, smart_read()
will detect the delimiter used in the file
if the argument delimiter = NULL
is passed in (the default).
If this does not work, you can override this argument:
smart_read('path/to/file', delimiter = '+')
Tom Elliott
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.