From c7b3905aff1aa993965d77558f1982588bee7841 Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Sun, 2 Jun 2024 12:09:57 +0200 Subject: [PATCH 1/6] Fix #425 no tests yet --- R/compression.R | 8 ++++++++ R/import.R | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/R/compression.R b/R/compression.R index ebf2521..6095980 100644 --- a/R/compression.R +++ b/R/compression.R @@ -135,3 +135,11 @@ parse_archive <- function(file, which, file_type, ...) { } NULL } + +.get_compressed_format <- function(cfile, file, file_type, format) { + if (file_type %in% c("gzip", "bzip2")) { + return(ifelse(isFALSE(missing(format)), tolower(format), get_info(find_compress(cfile)$file)$input)) + } + ## zip or tar formats, use the decompressed file path + return(ifelse(isFALSE(missing(format)), tolower(format), get_info(file)$input)) +} diff --git a/R/import.R b/R/import.R index 693d842..f41f891 100644 --- a/R/import.R +++ b/R/import.R @@ -135,8 +135,8 @@ import <- function(file, format, setclass = getOption("rio.import.class", "data. cfile <- file file <- f$file which <- ifelse(missing(which), 1, which) - format <- ifelse(isFALSE(missing(format)), tolower(format), get_info(file)$input) file <- parse_archive(cfile, which = which, file_type = f$compress) + format <- .get_compressed_format(cfile, file, f$compress, format) ## reset which if `file` is zip or tar. #412 which <- .reset_which(file_type = f$compress, which = which) } From c6ca320c903acd5aa6f8f0093d2fc62b669b5930 Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Sun, 2 Jun 2024 16:15:49 +0200 Subject: [PATCH 2/6] =?UTF-8?q?Add=20tests=20and=20B=C3=BCrokratie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DESCRIPTION | 2 +- NEWS.md | 6 ++++++ tests/testthat/test_compress.R | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 46f78be..2ac3174 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: rio Type: Package Title: A Swiss-Army Knife for Data I/O -Version: 1.1.0 +Version: 1.1.1 Authors@R: c(person("Jason", "Becker", role = "aut", email = "jason@jbecker.co"), person("Chung-hong", "Chan", role = c("aut", "cre"), email = "chainsawtiney@gmail.com", comment = c(ORCID = "0000-0002-6232-7530")), diff --git a/NEWS.md b/NEWS.md index 8631554..4b3fcf7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# rio 1.1.1 + +Bus fixes + +* Fix #425 for archive formats, the file extension of the input file is determined by the compressed file (like prior rio 1.1.0) + # rio 1.1.0 * CRAN release diff --git a/tests/testthat/test_compress.R b/tests/testthat/test_compress.R index 699c8b1..4df441b 100644 --- a/tests/testthat/test_compress.R +++ b/tests/testthat/test_compress.R @@ -103,3 +103,23 @@ test_that("tar export error for R < 4.0.3", { expect_error(export(iris, iris_path), "^Exporting") }) }) + +test_that("Wild zip and tar ref $425", { + skip_if(getRversion() >= "4.0.3") + withr::with_tempfile("test_files", fileext = c(".csv", ".zip"), code = { + filename <- test_files[1] + zip_file <- test_files[2] + write.csv(1, filename) + zip(zip_file, filename) + expect_error(rio::import(zip_file), NA) + }) + for (tar_format in c(".tar", ".tar.gz", ".tar.bz2")) { + withr::with_tempfile("test_files", fileext = c(".csv", tar_format), code = { + filename <- test_files[1] + tar_file <- test_files[2] + write.csv(1, filename) + tar(tar_file, filename) + expect_error(rio::import(tar_file), NA) + }) + } +}) From 94fca7bf12fc0516fed062075edb737595d58b48 Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Sun, 2 Jun 2024 16:19:21 +0200 Subject: [PATCH 3/6] Ik ben echt heel dom --- tests/testthat/test_compress.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test_compress.R b/tests/testthat/test_compress.R index 4df441b..aee2e06 100644 --- a/tests/testthat/test_compress.R +++ b/tests/testthat/test_compress.R @@ -105,7 +105,7 @@ test_that("tar export error for R < 4.0.3", { }) test_that("Wild zip and tar ref $425", { - skip_if(getRversion() >= "4.0.3") + skip_if(getRversion() < "4.0.3") withr::with_tempfile("test_files", fileext = c(".csv", ".zip"), code = { filename <- test_files[1] zip_file <- test_files[2] From 17319f6185b9b8f441fdf98fa0bfa22bd2a9900c Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Sun, 2 Jun 2024 16:36:12 +0200 Subject: [PATCH 4/6] Windows bug? Check on winbuilder --- tests/testthat/test_compress.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test_compress.R b/tests/testthat/test_compress.R index aee2e06..e90e1d5 100644 --- a/tests/testthat/test_compress.R +++ b/tests/testthat/test_compress.R @@ -105,7 +105,8 @@ test_that("tar export error for R < 4.0.3", { }) test_that("Wild zip and tar ref $425", { - skip_if(getRversion() < "4.0.3") + skip_if(getRversion() <= "4.0") + skip_on_os("windows") withr::with_tempfile("test_files", fileext = c(".csv", ".zip"), code = { filename <- test_files[1] zip_file <- test_files[2] From 7102903e69a8dd5a05678dc623b3b9b734c0677f Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Sun, 2 Jun 2024 16:54:49 +0200 Subject: [PATCH 5/6] How about this? --- tests/testthat/test_compress.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test_compress.R b/tests/testthat/test_compress.R index e90e1d5..f2f17d1 100644 --- a/tests/testthat/test_compress.R +++ b/tests/testthat/test_compress.R @@ -106,7 +106,7 @@ test_that("tar export error for R < 4.0.3", { test_that("Wild zip and tar ref $425", { skip_if(getRversion() <= "4.0") - skip_on_os("windows") + ##skip_on_os("windows") withr::with_tempfile("test_files", fileext = c(".csv", ".zip"), code = { filename <- test_files[1] zip_file <- test_files[2] @@ -114,12 +114,13 @@ test_that("Wild zip and tar ref $425", { zip(zip_file, filename) expect_error(rio::import(zip_file), NA) }) - for (tar_format in c(".tar", ".tar.gz", ".tar.bz2")) { + for (tar_format in c(".tar")) { withr::with_tempfile("test_files", fileext = c(".csv", tar_format), code = { filename <- test_files[1] tar_file <- test_files[2] write.csv(1, filename) - tar(tar_file, filename) + compress_out(tar_file, filename, type = "tar") + #tar(tar_file, filename, compression = "none") expect_error(rio::import(tar_file), NA) }) } From 8b82c9cb10417d92630d981ba4e40d8958a1a2a6 Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Sun, 2 Jun 2024 18:06:53 +0200 Subject: [PATCH 6/6] How about this this --- tests/testthat/test_compress.R | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test_compress.R b/tests/testthat/test_compress.R index f2f17d1..48d4d93 100644 --- a/tests/testthat/test_compress.R +++ b/tests/testthat/test_compress.R @@ -114,13 +114,12 @@ test_that("Wild zip and tar ref $425", { zip(zip_file, filename) expect_error(rio::import(zip_file), NA) }) - for (tar_format in c(".tar")) { - withr::with_tempfile("test_files", fileext = c(".csv", tar_format), code = { + for (tar_format in c("tar", "tar.gz", "tar.bz2")) { + withr::with_tempfile("test_files", fileext = c(".csv", paste0(".", tar_format)), code = { filename <- test_files[1] tar_file <- test_files[2] write.csv(1, filename) - compress_out(tar_file, filename, type = "tar") - #tar(tar_file, filename, compression = "none") + compress_out(tar_file, filename, type = tar_format) expect_error(rio::import(tar_file), NA) }) }