[R-sig-DB] DBI package
Paul Gilbert
pg||bert902 @end|ng |rom gm@||@com
Sat Oct 19 17:46:46 CEST 2013
On 13-10-17 11:02 PM, Hadley Wickham wrote:
>> 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.
Agreed, just pointing out that it does not fix the problem I mentioned,
which I think was the starting point for that thread.
>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.
Thanks for the suggestion, however, I remain a bit confused. The
function find_driver() seems like a direct replacement for dbConnect(),
using a string to identify the database driver. You would be supporting
what is a bad idea, and just changing the name of the function, which is
a make work project for everyone.
If you do put it in DBI you probably want a try() wrapper so that it
fails gracefully when the appropriate package is not attached.
Paul
>
> Hadley
>
>
More information about the R-sig-DB
mailing list