[R-sig-DB] DBI package

Hadley Wickham h@w|ckh@m @end|ng |rom gm@||@com
Fri Oct 18 05:02:24 CEST 2013


> I think Seth's proposal would mean that users would need to change the
> TSconnect calls to something like
>   con1 <- TSconnect(MySQL(), dbname="test")
>   con2 <- TSconnect(SQLite(), dbname="test")
>
> I don't object to making changes if they fix a problem, but I don't think
> this actually fixes the problem that I pointed out. The user session still
> needs to find the function MySQL() or SQLite(), which means my package need
> to indicate RMySQL or RSQLite as Depends rather than Imports.

Well, the problem is that relying on strings to identify database
drivers is not in general a good approach. For your code, you could do
something like:

find_driver <- function(name) {
  getExportedValue(paste0("R", name), name)()
}

setMethod("TSconnect",   signature(drv="character", dbname="character"),
   definition=function(drv, dbname, ...)
             TSconnect(find_driver(drv), dbname=dbname, ...))

It may be worthwhile to include find_driver in DBI.

Hadley


-- 
Chief Scientist, RStudio
http://had.co.nz/




More information about the R-sig-DB mailing list