inherits_any {rlang}R Documentation

Does an object inherit from a set of classes?

Description

Usage

inherits_any(x, class)

inherits_all(x, class)

inherits_only(x, class)

Arguments

x

An object to test for inheritance.

class

A character vector of classes.

Examples

obj <- structure(list(), class = c("foo", "bar", "baz"))

# With the _any variant only one class must match:
inherits_any(obj, c("foobar", "bazbaz"))
inherits_any(obj, c("foo", "bazbaz"))

# With the _all variant all classes must match:
inherits_all(obj, c("foo", "bazbaz"))
inherits_all(obj, c("foo", "baz"))

# The order of classes must match as well:
inherits_all(obj, c("baz", "foo"))

# inherits_only() checks that the class vectors are identical:
inherits_only(obj, c("foo", "baz"))
inherits_only(obj, c("foo", "bar", "baz"))

[Package rlang version 1.1.3 Index]