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

Matthew Dowle mdowle at mdowle.plus.com
Wed Nov 24 20:13:34 CET 2010


Try

  test(228, setClass("DTS4", representation(info="data.table")), "DTS4")

Then test() should print the error nicely that setClass is returning.

In test.data.table we only use try() for when the correct result is an
error and the test is that we get the right error message with a grep in
another test just afterwards. Otherwise we can leave test() to try().

Code that shouldn't fail can just be written (and would cause
test.data.table to stop then and there on error) or inside a test(). All
code returns something even if just NULL is the 3rd argument to test().

> Ok,
>
> The "strange" warnings had to be fixed, I just needed to
> `import(methods)` in the NAMESPACE file.
>
> These are the changes made:
>
> DESCRIPTION (added Imports and bumped version to 1.5.2):
> https://github.com/lianos/datatable/blob/master/pkg/DESCRIPTION
>
> NAMESPACE (see the S4-ization block up top):
> https://github.com/lianos/datatable/blob/master/pkg/NAMESPACE
>
> R/AllS4.R
> https://github.com/lianos/datatable/blob/master/pkg/R/AllS4.R
>
> test.data.table.R (tests 226-228)
> https://github.com/lianos/datatable/blob/master/pkg/R/test.data.table.R
>
> Problems:
> I can't get my test 228 to work when it is run through `R CMD check`.
> I keep getting the following problem:
>
> Test 228 ran without errors but failed check:
> [1] FALSE
>
> But if I load the new data.table library into an R session, then
> source() the test.data.table.R file, and run the test.data.table()
> function, everything works as expected.
>
> Not quite sure what's going on -- somehow the `x` in `if (x) return()`
> isn't evaluating to TRUE when it's run from the command line.
>
> Anyway, I'm going to see if this plays nice with the package I'm
> dev'ing that actually uses the S4-iztion of data.table to see if
> anything breaks further ...
>
> Thanks,
> -steve
> On Wed, Nov 24, 2010 at 11:51 AM, Matthew Dowle <mdowle at mdowle.plus.com>
> wrote:
>> Additions sound fine to me.
>>
>> Feel free to post the strange warnings. It's the least we can
>> do to help you contribute !
>>
>> Matthew
>>
>> "Steve Lianoglou" <mailinglist.honeypot at gmail.com> wrote in message
>> news:AANLkTimCy6zFcL3SXCVWewsCtrZL8OJkC79Eru8XBG-Y at mail.gmail.com...
>> Hi,
>>
>> Just an update: I'm working on adding this to package.
>>
>> When it's all said an done, I think we might actually have to add an
>> `Imports: methods` clause to the DESCRIPTION file, as well as an
>> `exportClass(data.table)` to the NAMESPACE.
>>
>> Would that be OK?
>>
>> I'm getting some strange warnings with R CMD check, so will sort that
>> out over the next few days when I can find the time.
>>
>> Thanks,
>> -steve
>>
>>
>> On Tue, Nov 23, 2010 at 11:35 AM, Matthew Dowle <mdowle at mdowle.plus.com>
>> wrote:
>>>
>>> Hi Steve,
>>>
>>> I don't know much about S4 but seems like a good idea, no objections
>>> from
>>> me either.
>>>
>>> Please click 'request to join' button on R-Forge project page for
>>> data.table, add some tests to the end of test.data.table.R, add
>>> something
>>> to the NEWS file, run 'R CMD build' and 'R CMD check', and (if ok)
>>> commit.
>>>
>>> Matthew
>>>
>>>
>>>> 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
>>>> _______________________________________________
>>>> datatable-help mailing list
>>>> datatable-help at lists.r-forge.r-project.org
>>>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
>>>>
>>>
>>>
>>>
>>
>>
>>
>> --
>> 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
>>
>>
>>
>> _______________________________________________
>> datatable-help mailing list
>> datatable-help at lists.r-forge.r-project.org
>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
>>
>
>
>
> --
> 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