[R] Simple inheritance check fails (integer from numeric)

Janko Thyson janko.thyson.rstuff at googlemail.com
Thu Jul 7 12:01:22 CEST 2011

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 

 > 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")


More information about the R-help mailing list