I'm trying to check the input I'm getting from a user to make sure it's the correct type. In this case, I'm fine with either integer
or double
as long as it's some kind of number.
I'm using checkmate::check_class()
like so with the following results:
> checkmate::check_class(4, "numeric")
[1] TRUE
> checkmate::check_class(as.integer(4), "numeric")
[1] "Must inherit from class 'numeric', but has class 'integer'"
My confusion is because numerous sources on the internet (notably this one from Hadley, in section 12.3.1) appear to be saying that both integer
and double
do in fact inherit from numeric
. So why does this fail?
Sidenote: check_class()
says it uses inherits()
under the hood so I tried using it explicitly and got the same results.
> inherits(4, "numeric")
[1] TRUE
> inherits(as.integer(4), "integer")
[1] TRUE
> inherits(as.integer(4), "numeric")
[1] FALSE
Thanks in advance for any help and clarification.