The aim of rio is to make data file input and output as easy as possible. export()
and import()
serve as a Swiss-army knife for painless data I/O for data from almost any file format by inferring the data structure from the file extension, natively reading web-based data sources, setting reasonable defaults for import and export, and relying on efficient data import and export packages. An additional convenience function, convert()
, provides a simple method for converting between file types.
Note that some of rio's functionality is provided by ‘Suggests’ dependendencies, meaning they are not installed by default. Use install_formats()
to make sure these packages are available for use.
References
datamods provides Shiny modules for importing data via rio
.
GREA provides an RStudio add-in to import data using rio.
Author
Maintainer: Chung-hong Chan chainsawtiney@gmail.com (ORCID)
Authors:
Jason Becker jason@jbecker.co
David Schoch david@schochastics.net (ORCID)
Thomas J. Leeper thosjleeper@gmail.com (ORCID)
Other contributors:
Geoffrey CH Chan gefchchan@gmail.com [contributor]
Christopher Gandrud [contributor]
Andrew MacDonald [contributor]
Ista Zahn [contributor]
Stanislaus Stadlmann [contributor]
Ruaridh Williamson ruaridh.williamson@gmail.com [contributor]
Patrick Kennedy [contributor]
Ryan Price ryapric@gmail.com [contributor]
Trevor L Davis trevor.l.davis@gmail.com [contributor]
Nathan Day nathancday@gmail.com [contributor]
Bill Denney wdenney@humanpredictions.com (ORCID) [contributor]
Alex Bokov alex.bokov@gmail.com (ORCID) [contributor]
Hugo Gruson (ORCID) [contributor]
Examples
# export
library("datasets")
export(mtcars, csv_file <- tempfile(fileext = ".csv")) # comma-separated values
export(mtcars, rds_file <- tempfile(fileext = ".rds")) # R serialized
export(mtcars, sav_file <- tempfile(fileext = ".sav")) # SPSS
# import
x <- import(csv_file)
y <- import(rds_file)
#> Warning: Missing `trust` will be set to FALSE by default for RDS in 2.0.0.
z <- import(sav_file)
# convert sav (SPSS) to dta (Stata)
convert(sav_file, dta_file <- tempfile(fileext = ".dta"))
# cleanup
unlink(c(csv_file, rds_file, sav_file, dta_file))