Skip to content

Commit

Permalink
Add the universal dummy which parameter to all import methods #326
Browse files Browse the repository at this point in the history
  • Loading branch information
chainsawriot committed Sep 12, 2023
1 parent 524b5e0 commit 3d0fbf7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/import_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ import_delim <-

#' @export
.import.rio_dta <- function(file, haven = TRUE,
convert.factors = FALSE, ...) {
convert.factors = FALSE, which = 1, ...) {
if (isTRUE(haven)) {
arg_reconcile(haven::read_dta,
file = file, ..., .docall = TRUE,
Expand Down Expand Up @@ -466,7 +466,7 @@ extract_html_row <- function(x, empty_value) {
}

#' @export
.import.rio_qs <- function(file, ...) {
.import.rio_qs <- function(file, which = 1, ...) {
.check_pkg_availability("qs")
qs::qread(file = file, ...)
}
23 changes: 23 additions & 0 deletions tests/testthat/test_import_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,29 @@ test_that("URL #294", {
expect_true("Africa" %in% x2[[2]]$continent)
})

test_that("Universal dummy `which` #326", {
formats <- c("xlsx", "dta", "sav", "csv", "csv2")
for (format in formats) {
tempzip <- tempfile(fileext = paste0(".", format, ".zip"))
rio::export(mtcars, tempzip, format = format)
expect_warning(rio::import(tempzip), NA)
expect_warning(rio::import_list(tempzip), NA)
}
})

test_that("Universal dummy `which` (Suggests) #326", {
skip_if_not_installed("qs")
skip_if_not_installed("arrow")
skip_if_not_installed("ods")
formats <- c("qs", "parquet", "ods")
for (format in formats) {
tempzip <- tempfile(fileext = paste0(".", format, ".zip"))
rio::export(mtcars, tempzip, format = format)
expect_warning(rio::import(tempzip), NA)
expect_warning(rio::import_list(tempzip), NA)
}
})

unlink("data.rdata")
unlink("mtcars.rds")
unlink("mtcars.csv.zip")

0 comments on commit 3d0fbf7

Please sign in to comment.