Alternate version of is() that supports multiple checks in a single call.

is2(x, class, .xname = getNameInParent(x))

Arguments

x

Object.

class

character(1). Object class.

.xname

Not intended to be used directly.

Value

logical(1).

Details

If a function named is.class exists, call is.class(x). If not, call is(x, class).

See also

Examples

is2(1:5, "character")
#> [1] FALSE #> Cause of failure: #> 1:5 is not of class 'character'; it has class 'integer'.
is2(matrix(1:5), "character")
#> [1] FALSE #> Cause of failure: #> matrix(1:5) is not of class 'character'; it has class 'integer matrix'.
is2(1:5, c("character", "list", "numeric"))
#> There were 2 failures: #> pos value cause #> 1 1 character class 'integer' is not 'character' #> 2 2 list class 'integer' is not 'list'
is2(mean, c("function", "data.frame"))
#> There was 1 failure: #> pos value cause #> 1 2 data.frame class 'closure function' is not 'data.frame'