gesistsa / rio

🐟 A Swiss-Army Knife for Data I/O
http://gesistsa.github.io/rio/
600 stars 76 forks source link

`export_list` only supports zip #415

Closed chainsawriot closed 4 months ago

chainsawriot commented 4 months ago

This line uses the default format

https://github.com/gesistsa/rio/blob/c86db70174bb9da81b7c4b6ee3f22dd9cbdb1c1e/R/export_list.R#L71

https://github.com/gesistsa/rio/blob/c86db70174bb9da81b7c4b6ee3f22dd9cbdb1c1e/R/compression.R#L16

archive should be checked for compression format.

chainsawriot commented 4 months ago

https://github.com/gesistsa/rio/blob/c86db70174bb9da81b7c4b6ee3f22dd9cbdb1c1e/R/export_list.R#L6

.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 commented 4 months ago

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.

https://github.com/gesistsa/rio/blob/ca019c903d470f3a3e6a6b21a511e336812e18dd/R/import_list.R#L120-L132