From maechler at stat.math.ethz.ch  Fri Mar 15 11:52:50 2013
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Fri, 15 Mar 2013 11:52:50 +0100
Subject: [Rd] removing union class
In-Reply-To: <20802.64086.443586.813352@stat.math.ethz.ch>
References: <CAHavPHES4xxZ6+wUXBG54ED8Y3OcOyxrCRUEMhJaB2hsepG3Xw@mail.gmail.com>
	<20802.64086.443586.813352@stat.math.ethz.ch>
Message-ID: <20802.64898.70553.300100@stat.math.ethz.ch>

>>>>> Martin Maechler <maechler at stat.math.ethz.ch>
>>>>>     on Fri, 15 Mar 2013 11:39:18 +0100 writes:

>>>>> Renaud Gaujoux <renaud at mancala.cbio.uct.ac.za>
>>>>>     on Wed, 13 Mar 2013 13:10:44 +0200 writes:

    >> Hi,
    >> I get the following error when trying to remove a union class:

    >>> setClassUnion('a', c('matrix', 'numeric'))
    >>> removeClass('a')
    >>> sessionInfo()
    >> R version 2.15.3 (2013-03-01)
    >> Platform: i686-pc-linux-gnu (32-bit)

    >> locale:
    >> [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
    >> [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
    >> [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
    >> [7] LC_PAPER=C                 LC_NAME=C
    >> [9] LC_ADDRESS=C               LC_TELEPHONE=C
    >> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

    >> attached base packages:
    >> [1] stats     graphics  grDevices utils     datasets  methods   base


    >> Is this normal? Am I doing something wrong?

    > Well,... you forgot to show the error (and the traceback) :

    >> setClassUnion('a', c('matrix', 'numeric'))
    >> removeClass('a')
    > Error in .getClassFromCache(Class, where) : node stack overflow

    >> traceback()
    > 1888: .getClassFromCache(Class, where)
    > 1887: getClass(cl)
    > 1886: checkAtAssignment("classRepresentation", "contains", "list")
    > 1885: .deleteSuperClass(cdef, superclass)
    > 1884: .removeSuperClass(subclass, superclass)
    > ..........
    > ..........
    > 3: .deleteSuperClass(cdef, superclass)
    > 2: .removeSuperClass(what, Class)
    > 1: removeClass("a")
    >> 

    > So that looks indeed like a bug in R's  removeClass() or its
    > helper functions.

or in the definition of  "matrix" and "array"  as   S4-like
classes.

The infinite recursion happens because 
    "matrix" has "array" as subclass
and "array"  has "matrix" ....
which by logic and usual set theory semantic would entail that
"array" and "matrix" must be the same class... 
:-)

Well have to see how to resolve this as cleanly as possible.
Martin

    > Note that this problem is somewhat dependent on the use of the 
    > infamous "matrix" class {not properly defined as a class in S3,
    > as it may or may not have dimnames, and then tried to be made S4
    > compatible "as well as possible" in the methods package, see

    > getClass("matrix")

    > Of course, I could not have thought of a realistic situation
    > where this was a problem, but then you exemplify one :

    >> Hadley, this is problematic for devtools, because load_all tries to cleanup
    >> S4 classes when an error occurs when loading a development package and
    >> crashes with no hint on the original error.

    >> Thank you.

    >> Bests,
    >> Renaud

    > Thank you for the report... although it would have been great if
    > it had come earlier, as we are approaching feature freeze for
    > 3.0.0 very rapidly.

    > Martin Maechler, ETH Zurich

    > ______________________________________________
    > R-devel at r-project.org mailing list
    > https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] removing union class
Martin Maechler