Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compression infrastructure is insufficiently tested #354

Closed
chainsawriot opened this issue Sep 8, 2023 · 2 comments
Closed

Compression infrastructure is insufficiently tested #354

chainsawriot opened this issue Sep 8, 2023 · 2 comments
Labels

Comments

@chainsawriot
Copy link
Collaborator

test_that("Recognize compressed file types", {
expect_true(rio:::find_compress("file.zip")$compress == "zip")
expect_true(rio:::find_compress("file.tar")$compress == "tar")
expect_true(rio:::find_compress("file.tar.gz")$compress == "tar")
expect_true(is.na(rio:::find_compress("file.gz")$compress))
expect_true(is.na(rio:::find_compress("file.notcompressed")$compress))
})
test_that("Export to compressed (zip)", {
e1 <- export(iris, "iris.csv.zip")
expect_true(e1 %in% dir())
})
test_that("Export to compressed (tar)", {
e2 <- export(iris, "iris.csv.tar")
expect_true(e2 %in% dir())
})
test_that("Import from compressed", {
expect_true(is.data.frame(import("iris.csv.zip")))
expect_true(is.data.frame(import("iris.csv.zip", which = 1)))
expect_true(is.data.frame(import("iris.csv.zip", which = "iris.csv")))
# tar export does not work due to: https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=16716
#expect_true(is.data.frame(import("iris.csv.tar")))
})

compress_out <- function(cfile, filename, type = c("zip", "tar", "gzip", "bzip2", "xz")) {

It only tests zip and tar. gzip (implemented in #123 ) is untested.

rio/R/import.R

Lines 112 to 116 in 81c0423

if (missing(format)) {
fmt <- get_ext(file)
if (fmt %in% c("gz", "gzip")) {
fmt <- tools::file_ext(tools::file_path_sans_ext(file, compression = FALSE))
file <- gzfile(file)

So do formats such as xz and bzip2.

@chainsawriot chainsawriot changed the title Compression infrastructure is untested Compression infrastructure is insufficiently tested Sep 8, 2023
@chainsawriot
Copy link
Collaborator Author

TODO

  • test bzip I and O
  • test xz I and O

@chainsawriot
Copy link
Collaborator Author

After #380, it is pretty easy to implement this.

test_that("Export to compressed (zip) / import", {
withr::with_tempfile("iris_path", fileext = ".csv.zip", code = {
e1 <- export(iris, iris_path)
expect_true(file.exists(iris_path))
expect_true(is.data.frame(import(iris_path)))
expect_true(is.data.frame(import(iris_path)))
expect_true(is.data.frame(import(iris_path, which = 1)))
base_file_name <- gsub("\\.zip", "", basename(iris_path))
expect_true(is.data.frame(import(iris_path, which = base_file_name)))
})
})

chainsawriot added a commit that referenced this issue Apr 25, 2024
But it doesn't fix #395 and #396
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant