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

export_list only supports zip #415

Closed
chainsawriot opened this issue May 14, 2024 · 2 comments
Closed

export_list only supports zip #415

chainsawriot opened this issue May 14, 2024 · 2 comments
Labels

Comments

@chainsawriot
Copy link
Collaborator

This line uses the default format

compress_out(archive, outfiles_normalized)

compress_out <- function(cfile, filename, type = c("zip", "tar", "tar.gz")) {

archive should be checked for compression format.

@chainsawriot
Copy link
Collaborator Author

chainsawriot commented May 15, 2024

#' directory, a path to a (new) directory, or a .zip/.tar file to compress all

.tar is promised in the doc.

list_of_dfs <- list(mtcars1 = mtcars[1:10,], mtcars2 = mtcars[11:20,], mtcars3 = mtcars[21:32,])

rio::export_list(list_of_dfs, file = "%s.csv", archive = y <- tempfile(fileext = ".csv.tar"))

file.exists(y)
#> [1] TRUE

## not tar
rio::import(y)
#> Warning in system(cmd, intern = TRUE): running command '/bin/tar -tf
#> '/tmp/RtmpM28RL3/file95e0562dc0081.csv.tar'' had status 2
#> Warning in extract_func(file, files = file_list[which], exdir = d): '/bin/tar
#> -xf '/tmp/RtmpM28RL3/file95e0562dc0081.csv.tar' -C
#> '/tmp/RtmpM28RL3/file95e05708ea197' 'NA'' returned error code 2
#> Error: 'file' has no extension

## but
file.copy(y, z <- tempfile(fileext = ".csv.zip"))
#> [1] TRUE

rio::import(z, which = 1)
#>     mpg cyl  disp  hp drat    wt  qsec vs am gear carb
#> 1  21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4
#> 2  21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4
#> 3  22.8   4 108.0  93 3.85 2.320 18.61  1  1    4    1
#> 4  21.4   6 258.0 110 3.08 3.215 19.44  1  0    3    1
#> 5  18.7   8 360.0 175 3.15 3.440 17.02  0  0    3    2
#> 6  18.1   6 225.0 105 2.76 3.460 20.22  1  0    3    1
#> 7  14.3   8 360.0 245 3.21 3.570 15.84  0  0    3    4
#> 8  24.4   4 146.7  62 3.69 3.190 20.00  1  0    4    2
#> 9  22.8   4 140.8  95 3.92 3.150 22.90  1  0    4    2
#> 10 19.2   6 167.6 123 3.92 3.440 18.30  1  0    4    4

##import(z, which = 2)
##import(z, which = 3)

Created on 2024-05-15 with reprex v2.1.0

@chainsawriot
Copy link
Collaborator Author

A short term solution is to clarify in the doc that only zip is supported. As a matter of fact, the corresponding import_list() only supports zip, not tar.

rio/R/import_list.R

Lines 120 to 132 in ca019c9

if (get_info(file)$format %in% c("zip")) {
if (missing(which)) {
whichnames <- utils::unzip(file, list = TRUE)[, "Name"]
which <- seq_along(whichnames)
names(which) <- .strip_exts(whichnames)
} else if (is.character(which)) {
whichnames <- utils::unzip(file, list = TRUE)[, "Name"]
whichnames <- whichnames[whichnames %in% which]
} else {
whichnames <- utils::unzip(file, list = TRUE)[, "Name"]
names(which) <- .strip_exts(whichnames)
}
}

chainsawriot added a commit that referenced this issue May 19, 2024
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