assertthat icon indicating copy to clipboard operation
assertthat copied to clipboard

confusing error message for is.numeric()

Open ThierryO opened this issue 10 years ago • 1 comments

The x is a matrix, the error message still refers to a vector.

library(assertthat)
x <- matrix(1:4, ncol = 2)
is.numeric(x) # returns TRUE
assert_that(is.numeric(x)) # returns TRUE
x <- matrix(letters, ncol = 2)
is.numeric(x) # returns FALSE
assert_that(is.numeric(x)) # returns error "Error: x is not a numeric or integer vector"

ThierryO avatar Aug 15 '15 13:08 ThierryO

@ThierryO I'm looking through assertthat issues today. Bet you forgot by now that you even wrote this one!

IMHO what you've reported is not actually a bug. base::is.numeric literally tests whether the thing you pass to is it a numeric/integer vector. This assertion fails for exactly the reason stated...you passed it an object full of numbers that is not a vector.

Does that make sense?

@hadley I think we can close this issue

jameslamb avatar Jun 23 '18 15:06 jameslamb