Skip to contents

These functions perform checks that assert the underlying class of objects passed to them.

  • check_inherits(): checks that object x is of class class using base::inherits()

  • check_inherits2(): checks that object x is of class class using base::.class2()

  • check_inherits_any(): checks that object x is at least one of the provided classes via rlang::inherits_any()

  • check_inherits_all(): checks that object x is all of the provided classes via rlang::inherits_all()

If validation fails for any of these functions, an error is thrown via check_abort() displaying a friendly error message.

Usage

check_inherits(
  x,
  class,
  arg = rlang::caller_arg(x),
  call = rlang::caller_env()
)

check_inherits2(
  x,
  class,
  arg = rlang::caller_arg(x),
  call = rlang::caller_env()
)

check_inherits_any(
  x,
  classes,
  arg = rlang::caller_arg(x),
  call = rlang::caller_env()
)

check_inherits_all(
  x,
  classes,
  arg = rlang::caller_arg(x),
  call = rlang::caller_env()
)

Arguments

x

The object to check.

class, classes

The name of the class or classes to use during checking.

arg

An argument name as a string. This argument will be mentioned in error messages as the input that is at the origin of a problem.

call

The execution environment of a currently running function, e.g. caller_env(). The function will be mentioned in error messages as the source of the error. See the call argument of abort() for more information.

Value

If checks pass, invisibly returns the provided x object. If checks fail, a condition error is thrown.