Skip to content

Commit 68327bb

Browse files
Adding (.qs2) functionality - Fix #471 (#472)
* Adding (.qs2) functionality - Fix #471 {qs2} is the successor to the {qs} package that has integrated functionality in {rio} currently. The author of the {qs} package will be deprecating it, so i wanted to get ahead of that and make a PR for his replacement package for {qs}. See below for reference to his deprecation announcement Note: other packages like {pins} have already begun to account for this move. qsbase/qs#103 * Added as contributor * Removing per suggestion * Made error on DESCRIPTION file for ctb, fixed now removing "Quick and Future-Proof" per suggestion * Updating sysdata.rds and re-rendering README * Final Touches: Re-render REAME, updating datatype descriptions to fix name collisions Also updated using devtools::document() which forced rio.Rd to be re-compiled --------- Co-authored-by: JMears_aces <[email protected]>
1 parent d914366 commit 68327bb

File tree

14 files changed

+117
-78
lines changed

14 files changed

+117
-78
lines changed

DESCRIPTION

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ Authors@R: c(person("Jason", "Becker", role = "aut", email = "[email protected]")
2727
comment=c(ORCID="0000-0002-5759-428X")),
2828
person("Alex", "Bokov", email = "[email protected]", role = "ctb",
2929
comment=c(ORCID="0000-0002-0511-9815")),
30-
person("Hugo", "Gruson", role = "ctb", comment = c(ORCID = "0000-0002-4094-1476"))
31-
)
30+
person("Hugo", "Gruson", role = "ctb", comment = c(ORCID = "0000-0002-4094-1476")),
31+
person("Jacob", "Mears", role = "ctb"))
3232
Description: Streamlined data import and export by making assumptions that
3333
the user is probably willing to make: 'import()' and 'export()' determine
3434
the data format from the file extension, reasonable defaults are used for
@@ -74,7 +74,8 @@ Suggests:
7474
arrow (>= 0.17.0),
7575
stringi,
7676
withr,
77-
nanoparquet
77+
nanoparquet,
78+
qs2 (>= 0.1.5)
7879
License: GPL-2
7980
VignetteBuilder: knitr
8081
Encoding: UTF-8

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ S3method(.export,rio_parquet)
2020
S3method(.export,rio_psv)
2121
S3method(.export,rio_pzfx)
2222
S3method(.export,rio_qs)
23+
S3method(.export,rio_qs2)
2324
S3method(.export,rio_r)
2425
S3method(.export,rio_rda)
2526
S3method(.export,rio_rdata)
@@ -58,6 +59,7 @@ S3method(.import,rio_parquet)
5859
S3method(.import,rio_psv)
5960
S3method(.import,rio_pzfx)
6061
S3method(.import,rio_qs)
62+
S3method(.import,rio_qs2)
6163
S3method(.import,rio_r)
6264
S3method(.import,rio_rda)
6365
S3method(.import,rio_rdata)

R/export.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#' \item Serialized R objects (.qs), using [qs::qsave()], which is
2929
#' significantly faster than .rds. This can be any R
3030
#' object (not just a data frame).
31+
#' \item Serialized R objects (.qs2), using [qs2::qs_save()]. This is the future-proof successor to using (.qs).
3132
#' \item "XBASE" database files (.dbf), using [foreign::write.dbf()]
3233
#' \item Weka Attribute-Relation File Format (.arff), using [foreign::write.arff()]
3334
#' \item Fixed-width format data (.fwf), using [utils::write.table()] with `row.names = FALSE`, `quote = FALSE`, and `col.names = FALSE`
@@ -100,10 +101,10 @@ export <- function(x, file, format, ...) {
100101
x <- as.data.frame(x)
101102
}
102103
if (!is.data.frame(x) && is.list(x) && length(x) == 1 && is.data.frame(x[[1]]) &&
103-
!format %in% c("xlsx", "html", "rdata", "rds", "json", "qs", "fods", "ods")) {
104+
!format %in% c("xlsx", "html", "rdata", "rds", "json", "qs", "qs2", "fods", "ods")) {
104105
x <- x[[1]] ## fix 385
105106
}
106-
if (!is.data.frame(x) && !format %in% c("xlsx", "html", "rdata", "rds", "json", "qs", "fods", "ods")) {
107+
if (!is.data.frame(x) && !format %in% c("xlsx", "html", "rdata", "rds", "json", "qs", "qs2", "fods", "ods")) {
107108
stop("'x' is not a data.frame or matrix", call. = FALSE)
108109
}
109110
if (format == "gz") {

R/export_methods.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,9 @@ export_delim <- function(file, x, fwrite = lifecycle::deprecated(), sep = "\t",
290290
.check_pkg_availability("qs")
291291
.docall(qs::qsave, ..., args = list(x = x, file = file))
292292
}
293+
294+
#' @export
295+
.export.rio_qs2 <- function(file, x, ...) {
296+
.check_pkg_availability("qs2")
297+
.docall(qs2::qs_save, ..., args = list(object = x, file = file))
298+
}

R/import.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#' \item Serialized R objects (.qs), using [qs::qread()], which is
3434
#' significantly faster than .rds. This can be any R
3535
#' object (not just a data frame).
36+
#' \item Serialized R objects (.qs2), using [qs2::qs_read()]. This is the future-proof successor to using (.qs).
3637
#' \item Epiinfo (.rec), using [foreign::read.epiinfo()]
3738
#' \item Minitab (.mtp), using [foreign::read.mtp()]
3839
#' \item Systat (.syd), using [foreign::read.systat()]
@@ -154,7 +155,7 @@ import <- function(file, format, setclass = getOption("rio.import.class", "data.
154155
}
155156

156157
# if R serialized object, just return it without setting object class
157-
if (inherits(file, c("rio_rdata", "rio_rds", "rio_json", "rio_qs")) && !inherits(x, "data.frame")) {
158+
if (inherits(file, c("rio_rdata", "rio_rds", "rio_json", "rio_qs", "rio_qs2")) && !inherits(x, "data.frame")) {
158159
return(x)
159160
}
160161
# otherwise, make sure it's a data frame (or requested class)

R/import_methods.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,9 @@ extract_html_row <- function(x, empty_value) {
425425
.check_pkg_availability("qs")
426426
.docall(qs::qread, ..., args = list(file = file))
427427
}
428+
429+
#' @export
430+
.import.rio_qs2 <- function(file, which = 1, ...) {
431+
.check_pkg_availability("qs2")
432+
.docall(qs2::qs_read, ..., args = list(file = file))
433+
}

R/sysdata.rda

43 Bytes
Binary file not shown.

README.md

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ coverage](https://codecov.io/gh/gesistsa/rio/graph/badge.svg)](https://app.codec
1414
The aim of **rio** is to make data file I/O in R as easy as possible by
1515
implementing two main functions in Swiss-army knife style:
1616

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

2323
## Installation
2424

@@ -135,54 +135,55 @@ install_formats()
135135

136136
The full list of supported formats is below:
137137

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

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

254255
### GUIs
255256

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

264264
### Similar packages
265265

266-
- [**reader**](https://cran.r-project.org/package=reader) handles
267-
certain text formats and R binary files
268-
- [**io**](https://cran.r-project.org/package=io) offers a set of
269-
custom formats
270-
- [**ImportExport**](https://cran.r-project.org/package=ImportExport)
271-
focuses on select binary formats (Excel, SPSS, and Access files) and
272-
provides a Shiny interface.
273-
- [**SchemaOnRead**](https://cran.r-project.org/package=SchemaOnRead)
274-
iterates through a large number of possible import methods until one
275-
works successfully
266+
- [**reader**](https://cran.r-project.org/package=reader) handles
267+
certain text formats and R binary files
268+
- [**io**](https://cran.r-project.org/package=io) offers a set of custom
269+
formats
270+
- [**ImportExport**](https://cran.r-project.org/package=ImportExport)
271+
focuses on select binary formats (Excel, SPSS, and Access files) and
272+
provides a Shiny interface.
273+
- [**SchemaOnRead**](https://cran.r-project.org/package=SchemaOnRead)
274+
iterates through a large number of possible import methods until one
275+
works successfully

data-raw/single.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,20 @@
624624
"input": "qs",
625625
"format": "qs",
626626
"type": "suggest",
627-
"format_name": "Serialized R objects (Quick)",
627+
"format_name": "Serialized R objects (qs)",
628628
"import_function": "qs::qread",
629629
"export_function": "qs::qsave",
630630
"note": ""
631631
},
632+
{
633+
"input": "qs2",
634+
"format": "qs2",
635+
"type": "suggest",
636+
"format_name": "Serialized R objects (qs2)",
637+
"import_function": "qs2::qs_save",
638+
"export_function": "qs2::qs_read",
639+
"note": "Replaces {qs} package which will be deprecated."
640+
},
632641
{
633642
"input": "xml",
634643
"format": "xml",

man/export.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)