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 fread or, if fread = FALSE, read.table with row.names = FALSE and stringsAsFactors = FALSE
Pipe-separated data (.psv), using fread or, if fread = FALSE, read.table with sep = '|', row.names = FALSE and stringsAsFactors = FALSE
Tab-separated data (.tsv), using fread or, if fread = FALSE, read.table with row.names = FALSE and stringsAsFactors = FALSE
SAS (.sas7bdat), using read_sas.
SPSS (.sav), using read_sav. If haven = FALSE, read.spss can be used.
Stata (.dta), using read_dta. If haven = FALSE, read.dta can be used.
SAS XPORT (.xpt), using read.xport.
SPSS Portable Files (.por), using read_por.
Excel (.xls and .xlsx), using read_excel. Use which to specify a sheet number. For .xlsx files, it is possible to set readxl = FALSE, so that read.xlsx can be used instead of readxl (the default).
R syntax object (.R), using dget
Saved R objects (.RData,.rda), using load for single-object .Rdata files. Use which to specify an object name for multi-object .Rdata files.
Serialized R objects (.rds), using readRDS
Epiinfo (.rec), using read.epiinfo
Minitab (.mtp), using read.mtp
Systat (.syd), using read.systat
"XBASE" database files (.dbf), using read.dbf
Weka Attribute-Relation File Format (.arff), using read.arff
Data Interchange Format (.dif), using read.DIF
Fortran data (no recognized extension), using read.fortran
Fixed-width format data (.fwf), using a faster version of read.fwf that requires a widths argument and by default in rio has stringsAsFactors = FALSE. If readr = TRUE, import will be performed using read_fwf, where widths should be: NULL, a vector of column widths, or the output of fwf_empty, fwf_widths, or fwf_positions.
gzip comma-separated data (.csv.gz), using read.table with row.names = FALSE and stringsAsFactors = FALSE
CSVY (CSV with a YAML metadata header) using read_csvy.
Feather R/Python interchange format (.feather), using read_feather
Fast storage (.fst), using read.fst
JSON (.json), using fromJSON
Matlab (.mat), using read.mat
OpenDocument Spreadsheet (.ods), using read_ods. Use which to specify a sheet number.
Single-table HTML documents (.html), using read_html. The data structure will only be read correctly if the HTML file can be converted to a list via as_list.
Shallow XML documents (.xml), using read_xml. The data structure will only be read correctly if the XML file can be converted to a list via as_list.
YAML (.yml), using yaml.load
Clipboard import (on Windows and Mac OS), using read.table with row.names = FALSE
Google Sheets, as Comma-separated data (.csv)
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.