[R-sig-DB] Add a "dbSendUpdate" function to DBI?

Hadley Wickham h@w|ckh@m @end|ng |rom gm@||@com
Thu Sep 4 18:26:27 CEST 2014


> I think this depends on the code. There are frequently situations where it
> is nice to have a function that is certain to return a logical value, so not
> have to catch exceptions and parse for all possibilities. (BTW, if error
> message text is to be returned then that can be set as an attribute to the
> logical value.) My feeling is it would be nice to have both, one function
> certain to return a logical, and one that will throw an error. If one is a
> simple wrapper to the other then only one method needs to be implemented and
> the DBI default can look after the other.

I think this is a philosophical API design decision, and it's a bad
idea to try and support both approaches. That makes it confusing how
you should approach a problem and more likely that you fail to catch
an important error.

If the API returns TRUE or throws an error, it's easy to write your
own wrapper to make it return TRUE or FALSE:

success <- function(x) {
  tryCatch(x, error = function(e) FALSE)
}

success(TRUE)
success(stop("!!"))

Hadley

-- 
http://had.co.nz/




More information about the R-sig-DB mailing list