[Rd] S4 coercion responsibility
Paul Gilbert
pgilbert at bank-banque-canada.ca
Mon Sep 15 14:56:06 CEST 2008
Should functions or the user be responsible for coercing an S4 object
argument containing the proper object (and thus should below be
considered a bug in the packages or not)?
The example is with RSQLite but the same thing happens with RMySQL, and
other DBI packages.
> library("RSQLite") Loading required package: DBI
> m <- dbDriver("SQLite")
> con <- dbConnect(m)
> setClass("SQLConPlus", contains=c("SQLiteConnection","integer"))
[1] "SQLConPlus"
> conPlus <- new("SQLConPlus", con, 1)
> dbListTables(con)
character(0)
> dbListTables(conPlus)
Error in sqliteExecStatement(con, statement, bind.data) :
RS-DBI driver: (invalid dbManager handle)
> dbListTables(as(conPlus, "SQLiteConnection"))
character(0)
>
The problem is happening in sqliteExecStatement which does
conId <- as(con, "integer")
but con only *contains* an SQLiteConnection and the other integer
causes confusion. If the line were
conId <- as(as(con, "SQLiteConnection"), "integer")
everything works.
I can work around this, but I am curious where responsibility for this
coercion should be.
Paul Gilbert
====================================================================================
La version française suit le texte anglais.
------------------------------------------------------------------------------------
This email may contain privileged and/or confidential in...{{dropped:26}}
More information about the R-devel
mailing list