This function imports a data frame or matrix from a data file with the file format based on the file extension (or the manually specified format, if format
is specified).
Comma-separated data (.csv), using data.table::fread()
Pipe-separated data (.psv), using data.table::fread()
Tab-separated data (.tsv), using data.table::fread()
SAS (.sas7bdat), using haven::read_sas()
SAS XPORT (.xpt), using haven::read_xpt()
SPSS (.sav), using haven::read_sav()
SPSS compressed (.zsav), using haven::read_sav()
.
Stata (.dta), using haven::read_dta()
SPSS Portable Files (.por), using haven::read_por()
.
Excel (.xls and .xlsx), using readxl::read_xlsx()
or readxl::read_xls()
. Use which
to specify a sheet number.
R syntax object (.R), using base::dget()
, see trust
below.
Saved R objects (.RData,.rda), using base::load()
for single-object .Rdata files. Use which
to specify an object name for multi-object .Rdata files. This can be any R object (not just a data frame), see trust
below.
Serialized R objects (.rds), using base::readRDS()
. This can be any R object (not just a data frame), see trust
below.
Serialized R objects (.qs), using qs::qread()
, which is
significantly faster than .rds. This can be any R
object (not just a data frame).
Epiinfo (.rec), using foreign::read.epiinfo()
Minitab (.mtp), using foreign::read.mtp()
Systat (.syd), using foreign::read.systat()
"XBASE" database files (.dbf), using foreign::read.dbf()
Weka Attribute-Relation File Format (.arff), using foreign::read.arff()
Data Interchange Format (.dif), using utils::read.DIF()
Fortran data (no recognized extension), using utils::read.fortran()
Fixed-width format data (.fwf), using a faster version of utils::read.fwf()
that requires a widths
argument and by default in rio has stringsAsFactors = FALSE
CSVY (CSV with a YAML metadata header) using data.table::fread()
.
Apache Arrow Parquet (.parquet), using nanoparquet::read_parquet()
Feather R/Python interchange format (.feather), using arrow::read_feather()
Fast storage (.fst), using fst::read.fst()
JSON (.json), using jsonlite::fromJSON()
Matlab (.mat), using rmatio::read.mat()
EViews (.wf1), using hexView::readEViews()
OpenDocument Spreadsheet (.ods, .fods), using readODS::read_ods()
or readODS::read_fods()
. Use which
to specify a sheet number.
Single-table HTML documents (.html), using xml2::read_html()
. There is no standard HTML table and we have only tested this with HTML tables exported with this package. HTML tables will only be read correctly if the HTML file can be converted to a list via xml2::as_list()
. This import feature is not robust, especially for HTML tables in the wild. Please use a proper web scraping framework, e.g. rvest
.
Shallow XML documents (.xml), using xml2::read_xml()
. The data structure will only be read correctly if the XML file can be converted to a list via xml2::as_list()
.
YAML (.yml), using yaml::yaml.load()
Clipboard import, using utils::read.table()
with row.names = FALSE
Google Sheets, as Comma-separated data (.csv)
GraphPad Prism (.pzfx) using pzfx::read_pzfx()
After importing metadata-rich file formats (e.g., from Stata or SPSS), it may be helpful to recode labelled variables to character or factor using characterize()
or factorize()
respectively.