Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Authors@R: c(person("Jason", "Becker", role = "aut", email = "[email protected]")
comment=c(ORCID="0000-0002-5759-428X")),
person("Alex", "Bokov", email = "[email protected]", role = "ctb",
comment=c(ORCID="0000-0002-0511-9815")),
person("Hugo", "Gruson", role = "ctb", comment = c(ORCID = "0000-0002-4094-1476"))
)
person("Hugo", "Gruson", role = "ctb", comment = c(ORCID = "0000-0002-4094-1476")),
person("Jacob", "Mears", role = "ctb"))
Description: Streamlined data import and export by making assumptions that
the user is probably willing to make: 'import()' and 'export()' determine
the data format from the file extension, reasonable defaults are used for
Expand Down Expand Up @@ -74,7 +74,8 @@ Suggests:
arrow (>= 0.17.0),
stringi,
withr,
nanoparquet
nanoparquet,
qs2 (>= 0.1.5)
License: GPL-2
VignetteBuilder: knitr
Encoding: UTF-8
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ S3method(.export,rio_parquet)
S3method(.export,rio_psv)
S3method(.export,rio_pzfx)
S3method(.export,rio_qs)
S3method(.export,rio_qs2)
S3method(.export,rio_r)
S3method(.export,rio_rda)
S3method(.export,rio_rdata)
Expand Down Expand Up @@ -58,6 +59,7 @@ S3method(.import,rio_parquet)
S3method(.import,rio_psv)
S3method(.import,rio_pzfx)
S3method(.import,rio_qs)
S3method(.import,rio_qs2)
S3method(.import,rio_r)
S3method(.import,rio_rda)
S3method(.import,rio_rdata)
Expand Down
5 changes: 3 additions & 2 deletions R/export.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#' \item Serialized R objects (.qs), using [qs::qsave()], which is
#' significantly faster than .rds. This can be any R
#' object (not just a data frame).
#' \item Serialized R objects (.qs2), using [qs2::qs_save()]. This is the future-proof successor to using (.qs).
#' \item "XBASE" database files (.dbf), using [foreign::write.dbf()]
#' \item Weka Attribute-Relation File Format (.arff), using [foreign::write.arff()]
#' \item Fixed-width format data (.fwf), using [utils::write.table()] with `row.names = FALSE`, `quote = FALSE`, and `col.names = FALSE`
Expand Down Expand Up @@ -100,10 +101,10 @@ export <- function(x, file, format, ...) {
x <- as.data.frame(x)
}
if (!is.data.frame(x) && is.list(x) && length(x) == 1 && is.data.frame(x[[1]]) &&
!format %in% c("xlsx", "html", "rdata", "rds", "json", "qs", "fods", "ods")) {
!format %in% c("xlsx", "html", "rdata", "rds", "json", "qs", "qs2", "fods", "ods")) {
x <- x[[1]] ## fix 385
}
if (!is.data.frame(x) && !format %in% c("xlsx", "html", "rdata", "rds", "json", "qs", "fods", "ods")) {
if (!is.data.frame(x) && !format %in% c("xlsx", "html", "rdata", "rds", "json", "qs", "qs2", "fods", "ods")) {
stop("'x' is not a data.frame or matrix", call. = FALSE)
}
if (format == "gz") {
Expand Down
6 changes: 6 additions & 0 deletions R/export_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,9 @@ export_delim <- function(file, x, fwrite = lifecycle::deprecated(), sep = "\t",
.check_pkg_availability("qs")
.docall(qs::qsave, ..., args = list(x = x, file = file))
}

#' @export
.export.rio_qs2 <- function(file, x, ...) {
.check_pkg_availability("qs2")
.docall(qs2::qs_save, ..., args = list(object = x, file = file))
}
3 changes: 2 additions & 1 deletion R/import.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#' \item Serialized R objects (.qs), using [qs::qread()], which is
#' significantly faster than .rds. This can be any R
#' object (not just a data frame).
#' \item Serialized R objects (.qs2), using [qs2::qs_read()]. This is the future-proof successor to using (.qs).
#' \item Epiinfo (.rec), using [foreign::read.epiinfo()]
#' \item Minitab (.mtp), using [foreign::read.mtp()]
#' \item Systat (.syd), using [foreign::read.systat()]
Expand Down Expand Up @@ -154,7 +155,7 @@ import <- function(file, format, setclass = getOption("rio.import.class", "data.
}

# if R serialized object, just return it without setting object class
if (inherits(file, c("rio_rdata", "rio_rds", "rio_json", "rio_qs")) && !inherits(x, "data.frame")) {
if (inherits(file, c("rio_rdata", "rio_rds", "rio_json", "rio_qs", "rio_qs2")) && !inherits(x, "data.frame")) {
return(x)
}
# otherwise, make sure it's a data frame (or requested class)
Expand Down
6 changes: 6 additions & 0 deletions R/import_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,9 @@ extract_html_row <- function(x, empty_value) {
.check_pkg_availability("qs")
.docall(qs::qread, ..., args = list(file = file))
}

#' @export
.import.rio_qs2 <- function(file, which = 1, ...) {
.check_pkg_availability("qs2")
.docall(qs2::qs_read, ..., args = list(file = file))
}
Binary file modified R/sysdata.rda
Binary file not shown.
140 changes: 70 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ coverage](https://codecov.io/gh/gesistsa/rio/graph/badge.svg)](https://app.codec
The aim of **rio** is to make data file I/O in R as easy as possible by
implementing two main functions in Swiss-army knife style:

- `import()` provides a painless data import experience by
automatically choosing the appropriate import/read function based on
file extension (or a specified `format` argument)
- `export()` provides the same painless file recognition for data
export/write functionality
- `import()` provides a painless data import experience by automatically
choosing the appropriate import/read function based on file extension
(or a specified `format` argument)
- `export()` provides the same painless file recognition for data
export/write functionality

## Installation

Expand Down Expand Up @@ -135,54 +135,55 @@ install_formats()

The full list of supported formats is below:

| Name | Extensions / “format” | Import Package | Export Package | Type | Note |
| :---------------------------------- | :---------------------------------- | :------------- | :------------- | :------ | :----------------------------- |
| Archive files (handled by tar) | tar / tar.gz / tgz / tar.bz2 / tbz2 | utils | utils | Default | |
| Bzip2 | bz2 / bzip2 | base | base | Default | |
| Gzip | gz / gzip | base | base | Default | |
| Zip files | zip | utils | utils | Default | |
| Ambiguous file format | dat | data.table | | Default | Attempt as delimited text data |
| CSVY (CSV + YAML metadata header) | csvy | data.table | data.table | Default | |
| Comma-separated data | csv | data.table | data.table | Default | |
| Comma-separated data (European) | csv2 | data.table | data.table | Default | |
| Data Interchange Format | dif | utils | | Default | |
| Epiinfo | epiinfo / rec | foreign | | Default | |
| Excel | excel / xlsx | readxl | writexl | Default | |
| Excel (Legacy) | xls | readxl | | Default | |
| Excel (Read only) | xlsm / xltx / xltm | readxl | | Default | |
| Fixed-width format data | fwf | readr | utils | Default | |
| Fortran data | fortran | utils | | Default | No recognized extension |
| Google Sheets | googlesheets | data.table | | Default | As comma-separated data |
| Minitab | minitab / mtp | foreign | | Default | |
| Pipe-separated data | psv | data.table | data.table | Default | |
| R syntax | r | base | base | Default | |
| SAS | sas / sas7bdat | haven | haven | Default | Export is deprecated |
| SAS XPORT | xport / xpt | haven | haven | Default | |
| SPSS | sav / spss | haven | haven | Default | |
| SPSS (compressed) | zsav | haven | haven | Default | |
| SPSS Portable | por | haven | | Default | |
| Saved R objects | rda / rdata | base | base | Default | |
| Serialized R objects | rds | base | base | Default | |
| Stata | dta / stata | haven | haven | Default | |
| Systat | syd / systat | foreign | | Default | |
| Tab-separated data | / tsv / txt | data.table | data.table | Default | |
| Text Representations of R Objects | dump | base | base | Default | |
| Weka Attribute-Relation File Format | arff / weka | foreign | foreign | Default | |
| XBASE database files | dbf | foreign | foreign | Default | |
| Apache Arrow (Parquet) | parquet | nanoparquet | nanoparquet | Suggest | |
| Clipboard | clipboard | clipr | clipr | Suggest | default is tsv |
| EViews | eviews / wf1 | hexView | | Suggest | |
| Fast Storage | fst | fst | fst | Suggest | |
| Feather R/Python interchange format | feather | arrow | arrow | Suggest | |
| Graphpad Prism | pzfx | pzfx | pzfx | Suggest | |
| HTML Tables | htm / html | xml2 | xml2 | Suggest | |
| JSON | json | jsonlite | jsonlite | Suggest | |
| Matlab | mat / matlab | rmatio | rmatio | Suggest | |
| OpenDocument Spreadsheet | ods | readODS | readODS | Suggest | |
| OpenDocument Spreadsheet (Flat) | fods | readODS | readODS | Suggest | |
| Serialized R objects (Quick) | qs | qs | qs | Suggest | |
| Shallow XML documents | xml | xml2 | xml2 | Suggest | |
| YAML | yaml / yml | yaml | yaml | Suggest | |
| Name | Extensions / “format” | Import Package | Export Package | Type | Note |
|:---|:---|:---|:---|:---|:---|
| Archive files (handled by tar) | tar / tar.gz / tgz / tar.bz2 / tbz2 | utils | utils | Default | |
| Bzip2 | bz2 / bzip2 | base | base | Default | |
| Gzip | gz / gzip | base | base | Default | |
| Zip files | zip | utils | utils | Default | |
| Ambiguous file format | dat | data.table | | Default | Attempt as delimited text data |
| CSVY (CSV + YAML metadata header) | csvy | data.table | data.table | Default | |
| Comma-separated data | csv | data.table | data.table | Default | |
| Comma-separated data (European) | csv2 | data.table | data.table | Default | |
| Data Interchange Format | dif | utils | | Default | |
| Epiinfo | epiinfo / rec | foreign | | Default | |
| Excel | excel / xlsx | readxl | writexl | Default | |
| Excel (Legacy) | xls | readxl | | Default | |
| Excel (Read only) | xlsm / xltx / xltm | readxl | | Default | |
| Fixed-width format data | fwf | readr | utils | Default | |
| Fortran data | fortran | utils | | Default | No recognized extension |
| Google Sheets | googlesheets | data.table | | Default | As comma-separated data |
| Minitab | minitab / mtp | foreign | | Default | |
| Pipe-separated data | psv | data.table | data.table | Default | |
| R syntax | r | base | base | Default | |
| SAS | sas / sas7bdat | haven | haven | Default | Export is deprecated |
| SAS XPORT | xport / xpt | haven | haven | Default | |
| SPSS | sav / spss | haven | haven | Default | |
| SPSS (compressed) | zsav | haven | haven | Default | |
| SPSS Portable | por | haven | | Default | |
| Saved R objects | rda / rdata | base | base | Default | |
| Serialized R objects | rds | base | base | Default | |
| Stata | dta / stata | haven | haven | Default | |
| Systat | syd / systat | foreign | | Default | |
| Tab-separated data | / tsv / txt | data.table | data.table | Default | |
| Text Representations of R Objects | dump | base | base | Default | |
| Weka Attribute-Relation File Format | arff / weka | foreign | foreign | Default | |
| XBASE database files | dbf | foreign | foreign | Default | |
| Apache Arrow (Parquet) | parquet | nanoparquet | nanoparquet | Suggest | |
| Clipboard | clipboard | clipr | clipr | Suggest | default is tsv |
| EViews | eviews / wf1 | hexView | | Suggest | |
| Fast Storage | fst | fst | fst | Suggest | |
| Feather R/Python interchange format | feather | arrow | arrow | Suggest | |
| Graphpad Prism | pzfx | pzfx | pzfx | Suggest | |
| HTML Tables | htm / html | xml2 | xml2 | Suggest | |
| JSON | json | jsonlite | jsonlite | Suggest | |
| Matlab | mat / matlab | rmatio | rmatio | Suggest | |
| OpenDocument Spreadsheet | ods | readODS | readODS | Suggest | |
| OpenDocument Spreadsheet (Flat) | fods | readODS | readODS | Suggest | |
| Serialized R objects (qs) | qs | qs | qs | Suggest | |
| Serialized R objects (qs2) | qs2 | qs2 | qs2 | Suggest | Replaces {qs} package which will be deprecated. |
| Shallow XML documents | xml | xml2 | xml2 | Suggest | |
| YAML | yaml / yml | yaml | yaml | Suggest | |

Additionally, any format that is not supported by **rio** but that has a
known R implementation will produce an informative error message
Expand Down Expand Up @@ -253,23 +254,22 @@ c("mtcars.tsv", "iris.tsv") %in% dir()

### GUIs

- [**datamods**](https://cran.r-project.org/package=datamods) provides
Shiny modules for importing data via `rio`.
- [**rioweb**](https://github.com/lbraglia/rioweb) that provides
access to the file conversion features of `rio`.
- [**GREA**](https://github.com/Stan125/GREA/) is an RStudio add-in
that provides an interactive interface for reading in data using
`rio`.
- [**datamods**](https://cran.r-project.org/package=datamods) provides
Shiny modules for importing data via `rio`.
- [**rioweb**](https://github.com/lbraglia/rioweb) that provides access
to the file conversion features of `rio`.
- [**GREA**](https://github.com/Stan125/GREA/) is an RStudio add-in that
provides an interactive interface for reading in data using `rio`.

### Similar packages

- [**reader**](https://cran.r-project.org/package=reader) handles
certain text formats and R binary files
- [**io**](https://cran.r-project.org/package=io) offers a set of
custom formats
- [**ImportExport**](https://cran.r-project.org/package=ImportExport)
focuses on select binary formats (Excel, SPSS, and Access files) and
provides a Shiny interface.
- [**SchemaOnRead**](https://cran.r-project.org/package=SchemaOnRead)
iterates through a large number of possible import methods until one
works successfully
- [**reader**](https://cran.r-project.org/package=reader) handles
certain text formats and R binary files
- [**io**](https://cran.r-project.org/package=io) offers a set of custom
formats
- [**ImportExport**](https://cran.r-project.org/package=ImportExport)
focuses on select binary formats (Excel, SPSS, and Access files) and
provides a Shiny interface.
- [**SchemaOnRead**](https://cran.r-project.org/package=SchemaOnRead)
iterates through a large number of possible import methods until one
works successfully
11 changes: 10 additions & 1 deletion data-raw/single.json
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,20 @@
"input": "qs",
"format": "qs",
"type": "suggest",
"format_name": "Serialized R objects (Quick)",
"format_name": "Serialized R objects (qs)",
"import_function": "qs::qread",
"export_function": "qs::qsave",
"note": ""
},
{
"input": "qs2",
"format": "qs2",
"type": "suggest",
"format_name": "Serialized R objects (qs2)",
"import_function": "qs2::qs_save",
"export_function": "qs2::qs_read",
"note": "Replaces {qs} package which will be deprecated."
},
{
"input": "xml",
"format": "xml",
Expand Down
1 change: 1 addition & 0 deletions man/export.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/import.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading