assertthat icon indicating copy to clipboard operation
assertthat copied to clipboard

is.scalar to include is.atomic?

Open landesfeind opened this issue 8 years ago • 1 comments

Hi, the test for scalar evaluates also complex data types to true. For example

assertthat::is.scalar(list("foo"))
[1] TRUE

This was quite unexpected to me, because it is also documented together with the test for atomic data types.

Is there a rationale not to test for the given value to be atomic? Otherwise I would propose to test:

assertthat::is.scalar <- function (x) {
    is.atomic(x) && length(x) == 1L
}

Thanks for your help, Manuel

landesfeind avatar Aug 28 '18 15:08 landesfeind

Also

assertthat::is.scalar(data.frame(x = 1:10))
[1] TRUE

is unexpected

jfkingiii avatar Dec 31 '21 21:12 jfkingiii