Re: [Rd] S4 coerce

From: Seth Falcon <sfalcon_at_fhcrc.org>
Date: Mon, 16 Jul 2007 22:06:44 -0700

Paul Gilbert <pgilbert_at_bank-banque-canada.ca> writes:

> (I am not sure if this is a bug or a request for a more understandable
> warning, or possible something obvious I should be posting on r-help.)
>
> I am trying to coerce an new class object to be a DBIConnection and it
> does not work the way I think it should:
>
> R version 2.5.1 (2007-06-27) ...
> > require("RMySQL") # or require("RSQLite")
> Loading required package: RMySQL
> Loading required package: DBI
> [1] TRUE
> > m <- dbDriver("MySQL") # or m <- dbDriver("SQLite")
> > con <- dbConnect(m, dbname="test")
> > dbGetQuery(con, "create table zzz (
> + vintage VARCHAR(20) NOT NULL,
> + alias VARCHAR(20) default NULL,
> + Documentation TEXT,
> + PRIMARY KEY (vintage)
> + );")
> NULL
> > dbListTables(con)
> [1] "zzz"
> > setClass("TSconnection", representation(con="DBIConnection",
> + vintage = "logical",
> + panel = "logical")
> + )
> [1] "TSconnection"
> > setAs("TSconnection", "DBIConnection", def = function(from) from_at_con)

I think things work as you expect up until this pint.

> > setIs("TSconnection", "DBIConnection", coerce = function(x)
> > x_at_con)

I'm confused about what you want to do here. If you want TSconnection to be a DBIConnection, why wouldn't you use inheritance?

   setClass("TSconnection", contains="DBIConnection", ...)

+ seth

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

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue 17 Jul 2007 - 05:12:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 17 Jul 2007 - 16:36:45 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.