Skip to contents

Checks if the argument is a list of expressions.

Usage

assert_expr_list(
  arg,
  required_elements = NULL,
  named = FALSE,
  optional = FALSE
)

Arguments

arg

A function argument to be checked

required_elements

A character vector of names that must be present in arg

named

If set to TRUE, an error is issued if not all elements of the list are named.

optional

Is the checked argument 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 of expressions. Otherwise, the input it returned invisibly.

Examples

library(rlang)

example_fun <- function(vars) {
  assert_expr_list(vars)
}
example_fun(exprs(DTHDOM = "AE", DTHSEQ = AESEQ))

try(example_fun(exprs("AE", DTSEQ = AESEQ, !!list("a"))))
#> Error in assert_expr_list(vars) : 
#>   All elements of `vars` must be an expression.
#> vars[[3]] = `list("a")` is of type list