ColinFay / attempt

Tools for defensive programming in R
Other
124 stars 12 forks source link

stop_if_none : behavior different than expected #17

Open apetit5108 opened 2 years ago

apetit5108 commented 2 years ago

stop_if_none doesn't behave like I expected. Shouldn't it be equivalent to stop_if_not(any()) ? I am a french speaker but that is how I understand the term "none" = "not any"

attempt::stop_if_none(c(T, T), msg = "Error") # No error, fine for me
attempt::stop_if_none(c(F, F), msg = "Error") # Error, fine for me
attempt::stop_if_none(c(T, F), msg = "Error") # Error, while I was expecting No error

attempt::stop_if_not(any(c(T, T)), msg = "Error") # No error
attempt::stop_if_not(any(c(F, F)), msg = "Error") # Error
attempt::stop_if_not(any(c(T, F)), msg = "Error") # No error
ColinFay commented 3 weeks ago

Thanks for reporting.

This is indeed a bug, attempt::stop_if_none(c(T, F), msg = "Error") should indeed throw no error.

Will fix this soon