[Rd] binary form of is() contradicts its unary form

Hervé Pagès hpages at fredhutch.org
Wed Nov 29 21:45:20 CET 2017


Yes, data.frame is not an S4 class but is(data.frame())
finds its super-classes anyway and without the need to wrap
it in asS4(). And "list' is one of the super-classes. Then
is(data.frame(), "list") contradicts this.

I'm not asking for a workaround. I already have one with
'class2 %in% is(object)' as reported in my original post.
'is(asS4(object), class2)' is maybe another one but, unlike
the former, it's not obvious that it will behave consistently
with unary is(). There could be some other surprise on the
way.

You're missing the point of my original post. Which is that
there is a serious inconsistency between the unary and binary
forms of is(). Maybe the binary form is right in case of
is(data.frame(), "list"). But then the unary form should not
return "list'. This inconsistency will potentially hurt anybody
who tries to do computations on a class hierarchy, especially
if the hierarchy is complex and mixes S4 and S3 classes. So I'm
hoping this can be addressed. Hope you understand.

Cheers,
H.


On 11/29/2017 12:21 PM, Suzen, Mehmet wrote:
> Hi Herve,
>
> Interesting observation with `setClass` but it is for S4.  It looks
> like `data.frame()` is not an S4 class.
>
>> isS4(data.frame())
> [1] FALSE
>
> And in your case this might help:
>
>> is(asS4(data.frame()), "list")
> [1] TRUE
>
> Looks like `is` is designed for S4 classes, I am not entirely sure.
>
> Best,
> -Mehmet
>
> On 29 November 2017 at 20:46, Hervé Pagès <hpages at fredhutch.org> wrote:
>> Hi Mehmet,
>>
>> On 11/29/2017 11:22 AM, Suzen, Mehmet wrote:
>>>
>>> Hi Herve,
>>>
>>> I think you are confusing subclasses and classes. There is no
>>> contradiction. `is` documentation
>>> is very clear:
>>>
>>> `With one argument, returns all the super-classes of this object's class.`
>>
>>
>> Yes that's indeed very clear. So if "list" is a super-class
>> of "data.frame" (as reported by is(data.frame())), then
>> is(data.frame(), "list") should be TRUE.
>>
>> With S4 classes:
>>
>>    setClass("A")
>>    setClass("B", contains="A")
>>
>>    ## Get all the super-classes of B.
>>    is(new("B"))
>>    # [1] "B" "A"
>>
>>    ## Does a B object inherit from A?
>>    is(new("B"), "A")
>>    # [1] TRUE
>>
>> Cheers,
>> H.
>>
>>>
>>> Note that object class is always `data.frame` here, check:
>>>
>>>   > class(data.frame())
>>> [1] "data.frame"
>>>   > is(data.frame(), "data.frame")
>>> [1] TRUE
>>>
>>> Best,
>>> Mehmet
>>>
>>>
>>>
>>>
>>>
>>> On 29 Nov 2017 19:13, "Hervé Pagès" <hpages at fredhutch.org
>>> <mailto:hpages at fredhutch.org>> wrote:
>>>
>>>      Hi,
>>>
>>>      The unary forms of is() and extends() report that data.frame
>>>      extends list, oldClass, and vector:
>>>
>>>         > is(data.frame())
>>>         [1] "data.frame" "list"       "oldClass"   "vector"
>>>
>>>         > extends("data.frame")
>>>         [1] "data.frame" "list"       "oldClass"   "vector"
>>>
>>>      However, the binary form of is() disagrees:
>>>
>>>         > is(data.frame(), "list")
>>>         [1] FALSE
>>>         > is(data.frame(), "oldClass")
>>>         [1] FALSE
>>>         > is(data.frame(), "vector")
>>>         [1] FALSE
>>>
>>>      while the binary form of extends() agrees:
>>>
>>>         > extends("data.frame", "list")
>>>         [1] TRUE
>>>         > extends("data.frame", "oldClass")
>>>         [1] TRUE
>>>         > extends("data.frame", "vector")
>>>         [1] TRUE
>>>
>>>      Who is right?
>>>
>>>      Shouldn't 'is(object, class2)' be equivalent
>>>      to 'class2 %in% is(object)'? Furthermore, is there
>>>      any reason why 'is(object, class2)' is not implemented
>>>      as 'class2 %in% is(object)'?
>>>
>>>      Thanks,
>>>      H.
>>>
>>>      --
>>>      Hervé Pagès
>>>
>>>      Program in Computational Biology
>>>      Division of Public Health Sciences
>>>      Fred Hutchinson Canc
>>>
>>> <https://urldefense.proofpoint.com/v2/url?u=https-3A__maps.google.com_-3Fq-3DFred-2BHutchinson-2BCanc-26entry-3Dgmail-26source-3Dg&d=DwMFaQ&c=eRAMFD45gAfqt84VtBcfhQ&r=BK7q3XeAvimeWdGbWY_wJYbW0WYiZvSXAJJKaaPhzWA&m=AptypGUf1qnpkFcOc1eU_vdGSHsush3RGVUyjk7yDu8&s=sTr3VPPxYCZLOtlBS3DToP4-Wi44EOLs99gJcV932b0&e=>er
>>>      Research Center
>>>      1100 Fairview Ave. N, M1-B514
>>>      P.O. Box 19024
>>>      Seattle, WA 98109-1024
>>>
>>>      E-mail: hpages at fredhutch.org <mailto:hpages at fredhutch.org>
>>>      Phone:  (206) 667-5791
>>>      Fax:    (206) 667-1319
>>>
>>>      ______________________________________________
>>>      R-devel at r-project.org <mailto:R-devel at r-project.org> mailing list
>>>      https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Ddevel&d=DwIFaQ&c=eRAMFD45gAfqt84VtBcfhQ&r=BK7q3XeAvimeWdGbWY_wJYbW0WYiZvSXAJJKaaPhzWA&m=Edo4xQQyNSdlhiJjtVDnOcunTA8a6KT5EN7_jowitP8&s=ES11eQ8qMdiYMc5X-SbEfQyy2VoX6MUfX0skN-QWunc&e=
>>>
>>> <https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Ddevel&d=DwMFaQ&c=eRAMFD45gAfqt84VtBcfhQ&r=BK7q3XeAvimeWdGbWY_wJYbW0WYiZvSXAJJKaaPhzWA&m=AptypGUf1qnpkFcOc1eU_vdGSHsush3RGVUyjk7yDu8&s=OzNPwqjAWVsXOGKMCmd4Fa7Udcm21ewfJmUN78LenQY&e=>
>>>
>>
>> --
>> Hervé Pagès
>>
>> Program in Computational Biology
>> Division of Public Health Sciences
>> Fred Hutchinson Cancer Research Center
>> 1100 Fairview Ave. N, M1-B514
>> P.O. Box 19024
>> Seattle, WA 98109-1024
>>
>> E-mail: hpages at fredhutch.org
>> Phone:  (206) 667-5791
>> Fax:    (206) 667-1319

-- 
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpages at fredhutch.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319



More information about the R-devel mailing list