assert_list_of: Is an Argument a List of Objects of a Specific S3 Class?

Description Usage Arguments Value Author(s) Examples

View source: R/assertions.R

Description

Checks if an argument is a list of objects inheriting from the S3 class specified.

Usage

1
assert_list_of(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 not a list or if arg is a list but its elements are not objects inheriting from class

Author(s)

Thomas Neitmann

Examples

1
2
3
4
5
6
7
8
9
example_fun <- function(list) {
  assert_list_of(list, "data.frame")
}

example_fun(list(mtcars, iris))

try(example_fun(list(letters, 1:10)))

try(example_fun(c(TRUE, FALSE)))

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