qsbase / qs

Quick serialization of R objects
405 stars 19 forks source link

Show error/warning if qread() fails because file doesn't exist? #4

Closed antspengy closed 5 years ago

antspengy commented 5 years ago

Hi

This is a great package, and really speeds up load times for my Shiny apps.

Just a minor issue/suggestion. If a user uses qread() to open a file that doesn't exist (i.e. usually because they've made a typo in the file name, like I did), no warning or error message currently appears. The user can check to see if the variable you are loading to is null but otherwise doesn't know it didn't work.

For example the code below shows no warning.

library(qs)
test <- qread("imaginary_file.q")

It'd be nice if it could show a similar error message to read_csv which gives the error:

library(readr)
test <- read_csv("imaginary_file.csv")
#> Error: 'imaginary_file.csv' does not exist in current working directory ('/tmp/RtmpBMDlXz').

Thanks, and keep up the good work!

traversc commented 5 years ago

Thanks! I have this fixed in the development version here on github. On the R side:

c_qread(normalizePath(file, mustWork=FALSE), use_alt_rep, nthreads)

On the C side:

if(!myFile) {
    throw exception("Failed to open file");
}

I'm hoping to submit an update to CRAN soon.

traversc commented 5 years ago

@antspengy It's updated on CRAN if you 'd like to check it out :)