gesistsa / rio

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

Uninformative error message for missing files in import_list #389

Closed NickCH-K closed 4 months ago

NickCH-K commented 4 months ago

When import_list() is passed a filename that does not exist, it gives a fairly uninformative error message. Changing this to match the import() error message would be ideal.

not_a_file = 'nope.csv'

# Informative:
import(not_a_file)
# Error: No such file: nope.csv

# Not informative
import_list(c(not_a_file, not_a_file))
# Warning messages:
# 1: In FUN(X[[i]], ...) : Import failed for nope.csv
# 2: In structure(out, filename = thisfile) :
#  Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
#  Consider 'structure(list(), *)' instead.
# 3: In FUN(X[[i]], ...) : Import failed for nope.csv
# 4: In structure(out, filename = thisfile) :
 #  Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
 # Consider 'structure(list(), *)' instead.

If I run it in Quarto/Rmarkdown it's even more confusing as the "import failed for nope.csv" part doesn't show up, it's just the "Calling structure(NULL..." parts.

chainsawriot commented 4 months ago

@NickCH-K Thank you for reporting this.

I think there is one subtle difference between import() and import_list(). For import_list(), missing files are ignored and the messages are actually warnings. But I agree with you that the messages are confusing.

TODOS

chainsawriot commented 4 months ago
chainsawriot commented 4 months ago

@NickCH-K Thank you very much once again for reporting this. This is the current behavior.

require(rio)
#> Loading required package: rio

not_a_file <- "nope.csv"

import(not_a_file)
#> Error: No such file: nope.csv

import_list(c(not_a_file, "notavailable.csv"))
#> Warning: Import failed for nope.csv
#> Warning: Import failed for notavailable.csv
#> $nope
#> NULL
#> 
#> $notavailable
#> NULL

is_a_file <- tempfile(fileext = ".csv")
export(head(iris), is_a_file)

import_list(c(not_a_file, is_a_file))
#> Warning: Import failed for nope.csv
#> $nope
#> NULL
#> 
#> $file1700316aa3926
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1          5.1         3.5          1.4         0.2  setosa
#> 2          4.9         3.0          1.4         0.2  setosa
#> 3          4.7         3.2          1.3         0.2  setosa
#> 4          4.6         3.1          1.5         0.2  setosa
#> 5          5.0         3.6          1.4         0.2  setosa
#> 6          5.4         3.9          1.7         0.4  setosa

Created on 2024-03-07 with reprex v2.1.0