[R-sig-DB] default driver and connection

Seth Falcon @|@|con @end|ng |rom |hcrc@org
Thu Jul 19 19:32:07 CEST 2007


"Gabor Grothendieck" <ggrothendieck using gmail.com> writes:
> Now perhaps its enough to check for specific load packages and it is
> convenient. On the other hand it would be even more convincing that the
> user wanted to use a particular database it they had actually loaded the
> driver for it regardless of which library calls had been made -- although
> admittedly the user would then have to issue another statement, the
> dbDriver statement, so its slightly less convenient than what we
> have above.

How about a function in your package that sets the default db driver:

   setDefaultDb("MySQL")

This function could set a value in an environment object in your
package's namespace.  Users could load your package and call this
function in their .Rprofile for added convenience.  IMO relying on
packages being loaded (or not) is fragile.

> The next level is that we suppose we want to handle any database
> including SQLite, MySQL and other databases in the future that have
> not even been implemented with R drivers yet so its not possible to
> list them all.

setDefaultDb seems to solve this.

>> dbListAllCons = function() {
>>    drivers = list(SQLite(), MySQL())
>>    unlist(lapply(drivers, dbListConnections))
>> }
>>
>
> That would work although there could be other types of databases too
> including drivers not yet written or contemplated and the above requires
> that we know ahead of time what they all could be.

I'm with you as far as desiring well factored code, but honestly it
isn't like new DB drivers are popping up all over the place (when was
the last time a new driver was introduced?).  So listing them out
isn't going to be so bad in practice.

+ seth

-- 
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
http://bioconductor.org




More information about the R-sig-DB mailing list