tidyverse / vroom

Fast reading of delimited files
https://vroom.r-lib.org
Other
620 stars 60 forks source link

`vroom` does not work on list of connections #509

Closed bart1 closed 1 year ago

bart1 commented 1 year ago

I was following this example from the vignette but it seems vroom does not accept a list of connection I get the following message

> vroom::vroom(list(file("file1.csv"), file("file2.csv")))
Error in enc2utf8(path) : argument is not a character vector

https://github.com/tidyverse/vroom/blob/89b6aac8c9c07981a52c28251578deca11810ebd/vignettes/vroom.Rmd#L113-L118

bairdj commented 1 year ago

Reprex for this issue

library(vroom)
#> Warning: package 'vroom' was built under R version 4.2.3
library(purrr)

archive_path <- "test_archive.zip"
connections <- map(unzip(archive_path, list = TRUE)$Name, ~ unz(archive_path, .x))

print(connections)
#> [[1]]
#> A connection with                                           
#> description "test_archive.zip:file_001.csv"
#> class       "unz"                          

#> mode        "r"                            
#> text        "text"                         
#> opened      "closed"                       
#> can read    "yes"                          
#> can write   "yes"                          
#> 
#> [[2]]
#> A connection with                                           
#> description "test_archive.zip:file_002.csv"
#> class       "unz"                          
#> mode        "r"                            
#> text        "text"                         
#> opened      "closed"                       
#> can read    "yes"                          
#> can write   "yes"

vroom(connections)
#> Error in enc2utf8(path): argument is not a character vector

Created on 2023-09-15 with reprex v2.0.2

File: test_archive.zip

I believe the issue is that the check for connection objects in standardise_path does not handle a list of connections, only a single object https://github.com/tidyverse/vroom/blob/89b6aac8c9c07981a52c28251578deca11810ebd/R/path.R#L29C12-L29C12