[datatable-help] Playing nice(r) with S4?

Steve Lianoglou mailinglist.honeypot at gmail.com
Tue Nov 23 17:14:13 CET 2010


Hi Tom,

On Tue, Nov 23, 2010 at 10:53 AM, Tom Short <tshort.rlists at gmail.com> wrote:
> On Tue, Nov 23, 2010 at 10:33 AM, Steve Lianoglou
> <mailinglist.honeypot at gmail.com> wrote:
>> Hi all,
>>
>> Can we include some functions/declarations so that data.table objects
>> can be used in S4 classes?
>
> Steve, S4 has always scared me off, but if we can do something easy
> like that to help users, we probably should.

At the start, it did for me as well, but I think I (largely) have the
hang of it ... I wouldn't say I'm an expert, though.

> Do we have to require any other packages?

Not as far as I know. Usually a package that defines S4 classes and
such is required to import the 'methods' package, but I'm not sure if
it's necessary here.

I simply just `svn up`d my data.table repo and added the AllS4.R as
written above, then `R CMD INSTALL`ed it, and everything was kosher --
no warnings or anything and it works as expected.

> My only comment is related to the data.table(from) in the setAs
> function. Do you want that to be as.data.table(from)? The latter is
> probably faster but does less error checking and auto-conversions of
> columns.

Sure -- I'm largely indifferent on that, so whatever is more idiomatic
for the data.table devs probably will make the most sense.

Maybe for consistency sake, one would add:

setAs("data.table", "data.frame"), function(from) {
  as.data.frame(from) ## or whatever
})

So we can go back the other way and convert a data.table back to a
data.frame via `as(dt, "data.frame")`

-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact


More information about the datatable-help mailing list