[Bioc-devel] Problem with setClassUnion and DelayedArray
Michael Lawrence
l@wrence@mich@el @ending from gene@com
Thu Oct 11 05:11:45 CEST 2018
This underscores how setClassUnion() can lead to unintended consequences.
Inheritance is an extreme form of coupling, and subclasses are expected to
obey the contract specified by the super class. By defining a class union,
the developer is essentially inventing a contract without any commitment of
compliance by the members of the union and all of their descendants,
including private classes. In some cases, like forming a union between some
class and "NULL" for optional slots, unions are safe and useful in
practice. In more complex cases, there is greater risk of making invalid
assumptions.
In this specific case, you might want to take the precedent set by
SummarizedExperiment and rely on duck typing for matrix-like objects and
avoid the union entirely.
Michael
On Wed, Oct 10, 2018 at 11:51 AM Elizabeth Purdom <epurdom using stat.berkeley.edu>
wrote:
> Hello,
>
> I am using `setClassUnion` in my package `clusterExperiment` in the
> following code to allow for either matrix or DelayedArray:
>
> setClassUnion("matrixOrHDF5",members=c("matrix", "DelayedArray"))
>
> This causes the following warning in checking my package:
>
> Warning: subclass "DelayedArray1" of class "DelayedArray" is not local and
> cannot be updated for new inheritance information; consider setClassUnion()
>
> I’ve gotten this warning in other settings, and I believe it is due to the
> fact that setClassUnion works on the subclasses of the members, so if you
> give the argument `members=c(“X”,”Y”)` and you haven’t imported into your
> package all of the subclasses of “X” and “Y” it is warning you those
> non-imported classes haven’t been dealt with (though if so, I’d say the
> warning is awfully cryptic, especially since it says to use `setClassUnion`
> as a solution). In my other cases, I have just gone ahead and imported all
> of the subclasses from the package that defines the member classes and have
> gotten rid of the message (in the past it hasn’t been so many). But
> “DelayedArray1” is not an exported class of the DelayedArray package so
> that is not an option here.
>
> I have been just ignoring this warning, since I understand (I think) the
> warning, I can’t do anything about it, and am not concerned about it since
> this new class is only used internally by my function for the slot
> definition. And I don’t think the user sees this generally. But given that
> we’re coming up on a release I thought I would ask if there’s anything I
> can do to get rid of this warning! Or can I go with my first instinct and
> safely ignore it?
>
> Thanks,
> Elizabeth Purdom
>
> _______________________________________________
> Bioc-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel
>
[[alternative HTML version deleted]]
More information about the Bioc-devel
mailing list