assert_s3_class: Is an Argument an Object of a Specific S3 Class?

Description Usage Arguments Value Author(s) Examples

View source: R/assertions.R

Description

Checks if an argument is an object inheriting from the S3 class specified.

Usage

1
assert_s3_class(arg, class, optional = TRUE)

Arguments

arg

A function argument to be checked

class

The S3 class to check for

optional

Is the checked parameter optional? If set to FALSE and arg is NULL then an error is thrown

Value

The function throws an error if arg is an object which does not inherit from class

Author(s)

Thomas Neitmann

Examples

1
2
3
4
5
6
7
8
9
example_fun <- function(obj) {
  assert_s3_class(obj, "factor")
}

example_fun(as.factor(letters))

try(example_fun(letters))

try(example_fun(1:10))

epijim/admiral documentation built on Feb. 13, 2022, 12:15 a.m.