[R] Simple inheritance check fails (integer from numeric)
David Winsemius
dwinsemius at comcast.net
Thu Jul 7 16:09:53 CEST 2011
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
More information about the R-help
mailing list