[R-sig-DB] dbDriver("name")

Hadley Wickham h@w|ckh@m @end|ng |rom gm@||@com
Tue Oct 22 20:40:12 CEST 2013


>> Here's a first stab at it. I think it should work for the majority of
>> existing packages, regardless of whether they're loaded or not:
>
> I'm not sure if it is a good idea or not to find drivers that are not loaded
> or attached. This may cause more problems than it adds simplifications?
> Would you load or attach the packages in which the drivers are found? You
> and others probably understand the implications better than I do.

Oh, probably not. I've changed it to use:

is_attached <- function(x) {
  x %in% loadedNamespaces()
}

> Possibly one of my comments initiated the findDriver() effort, so let me
> give the context in which I have been doing something a bit similar. I look
> through a list of loaded/attached packages for a particular database, with a
> function  called like this:
>
>   con <- TSfinddb(dbname="ets",
>               driverOrder=c("MySQL", "SQLite", "PostgreSQL"))
>
> which attempts a dbConnect for each driver string, looking for the database
> "ets". But I just look though attached or loaded packages and the database
> may not exist even if the package is loaded, so I need to wrap the dbConnect
> calls in try().

I do a similar thing in dplyr when looking for test databases - I
think it's probably relatively common task for package authors, but
less common for package users.

Hadley


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




More information about the R-sig-DB mailing list