Janko Thyson
2011-Jul-07 10:01 UTC
[R] Simple inheritance check fails (integer from numeric)
Dear list, In a function, I don't care if my input has class 'integer' or 'numeric', so I wanted to use 'inherits()' to control for that. However, this function tells me that an actual object of class 'integer' does not inherit from class 'numeric'. The class def of 'integer' does state 'numeric' as one of the superclasses. Isn't that somewhat inconsistent? > getClass("integer") Class "integer" [package "methods"] No Slots, prototype of class "integer" Extends: "numeric", "vector", "data.frameRowLabels" > a <- 1:3 > class(a) [1] "integer" > inherits(a, "numeric") [1] FALSE Regards, Janko
David Winsemius
2011-Jul-07 14:09 UTC
[R] Simple inheritance check fails (integer from numeric)
On Jul 7, 2011, at 6:01 AM, Janko Thyson wrote:> Dear list, > > In a function, I don't care if my input has class 'integer' or > 'numeric', so I wanted to use 'inherits()' to control for that. > > However, this function tells me that an actual object of class > 'integer' does not inherit from class 'numeric'. The class def of > 'integer' does state 'numeric' as one of the superclasses. Isn't > that somewhat inconsistent? > > > getClass("integer") > Class "integer" [package "methods"] > > No Slots, prototype of class "integer" > > Extends: "numeric", "vector", "data.frameRowLabels" > > > a <- 1:3 > > class(a) > [1] "integer" > > > inherits(a, "numeric") > [1] FALSE >> a <- 1:3 > is.numeric(a) [1] TRUE -- David Winsemius, MD West Hartford, CT
Maybe Matching Threads
- reference classes: question on inheritance
- Feature request: mixing `...` (three dots) with other formal arguments in S4 methods
- Reference Classes: shortcut like 'isS4' for Ref Classes?
- Feature request: mixing `...` (three dots) with other formal arguments in S4 methods
- Bug or feature: using "ANY" as a generic field class (was: '[R] Is there a (virtual) class that all R objects inherit from?)