Examples for 'rlang::inherits_any'


Does an object inherit from a set of classes?

Aliases: inherits_any inherits_all inherits_only

Keywords:

### ** Examples

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
inherits_any(obj, c("foo", "bazbaz"))
[1] TRUE
# With the _all variant all classes must match:
inherits_all(obj, c("foo", "bazbaz"))
[1] FALSE
inherits_all(obj, c("foo", "baz"))
[1] TRUE
# The order of classes must match as well:
inherits_all(obj, c("baz", "foo"))
[1] FALSE
# inherits_only() checks that the class vectors are identical:
inherits_only(obj, c("foo", "baz"))
[1] FALSE
inherits_only(obj, c("foo", "bar", "baz"))
[1] TRUE

[Package rlang version 1.1.4 Index]