inherits_any() is like base::inherits() but is more explicit
about its behaviour with multiple classes. If classes contains
several elements and the object inherits from at least one of
them, inherits_any() returns TRUE.
inherits_all() tests that an object inherits from all of the
classes in the supplied order. This is usually the best way to
test for inheritance of multiple classes.
inherits_only() tests that the class vectors are identical. It
is a shortcut for identical(class(x), class).
inherits_any(x, class) inherits_all(x, class) inherits_only(x, class)
| x | An object to test for inheritance. |
|---|---|
| class | A character vector of classes. |
obj <- structure(list(), class = c("foo", "bar", "baz")) # With the _any variant only one class must match: inherits_any(obj, c("foobar", "bazbaz"))#> [1] FALSE#> [1] TRUE#> [1] FALSE#> [1] TRUE#> [1] FALSE#> [1] FALSE#> [1] TRUE