check_types {erify}R Documentation

Check Each Item's Type

Description

Check if each item of an argument has valid type, and if not, generate an error message.

Usage

check_types(
  x,
  valid,
  name = NULL,
  general = NULL,
  specific = NULL,
  supplement = NULL,
  ...
)

Arguments

x

The argument to check, which must be a list.

valid

A character vector which contains the valid types.

name

A single character which gives the argument's name. The name is used in the error message. By default, the name of the argument passed to argument x is captured automatically.

general

Optional. A single character which is used to give a general statement of the error incurred. By default, this is generated automatically.

specific

Optional. A single character which gives a detailed description of the error. glue::glue() syntax can be used, see "Examples" section. By default, this is generated automatically.

supplement

Optional. A (named) character vector which gives some additional information about the error. The names are used to create bullets, see throw(). By default, this is left empty.

...

Optional. Additional arguments which can be retrieved with tryCatch().

Value

returns an invisible NULL if the argument is valid, or generates an error message.

See Also

"Examples" section in check_type() for how to customize error message and how to add and retrieve additional arguments.

vignette("erify") for a gentle introduction to this package.

Examples

## Not run: 
# argument to check
arg <- as.list(1:10)

check_types(arg, "character")

# customize error message with `glue::glue()` syntax
specific <- "`{name}[[{i}]]` is an {feature}, oh my god!"
check_types(arg, "character",  specific = specific)

## End(Not run)

[Package erify version 0.6.0 Index]