hadley / strict

Make R a little bit stricter
235 stars 10 forks source link

Don't allow load function for rds file #29

Open pgensler opened 7 years ago

pgensler commented 7 years ago

Double clicking a .rds file will automatically open the file with a load function call, which throws a very terse error:

t <- load("/Users/petergensler/Downloads/homedata_lesson1_clean.rds")
Error in load("/Users/petergensler/Downloads/homedata_lesson1_clean.rds") : 
  bad restore file magic number (file may be corrupted) -- no data loaded
In addition: Warning message:
file ‘homedata_lesson1_clean.rds’ has magic number 'X'
  Use of save versions prior to 2 is deprecated 

Maybe forcing a user to explicitly use read_rds when reading in a .rds file is a good idea?

##works fine
t <- readr::read_rds("/Users/petergensler/Downloads/homedata_lesson1_clean.rds")  
hadley commented 7 years ago

Not sure you're filing this in the right place?

pgensler commented 7 years ago

Correct me if I'm wrong, but I'm pretty sure this is the intent of the package:

"The goal of strict to make R behave a little more strictly, making base functions more likely to throw an error rather than returning potentially ambiguous results."

I don't know about you, but having a "magic number" error is not exactly the easiest error to understand and I would argue it's somewhat ambiguous, and does not really make me "fall into a pit of success". Is the intent of the package to make the errors in R more informative?

Perhaps I am mislead, but isn't the point of the package meant to give stricter (and more informative errors), so that one is able to succeed in R (fail fast, and often mentality)?

hadley commented 7 years ago

But the code is generated by double clicking, which I have no control over.

pgensler commented 7 years ago

I understand your point, which, to be fair the issue is more about how the R GUI behaves with .rds files.

I still think it would be helpful to create a wrapper around the original error, which forces the user to always use readRDS() at the very least for reading in .rds files.

Maybe a better question to ask is this: is using readRDS always applicable to reading in .RDS files? Should you use a different approach? Even if you called mean(foorbar.rds), would strict return an informative error?

I understand you don't want to make a wrapper around all of the existing error messages in R, but I think it would strongly benefit users who are maybe new, or simply are trying to find a solution to reading in a file.

mungojam commented 6 years ago

@pgensler, sounds like a bug in whichever IDE you are using which ought to be fixed. Is it RStudio?