Check if an argument is a number in an interval, and if not, generate an error message.

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

Arguments

x

The argument to check, which can be any object.

valid

A numeric vector of length 2, which represents the valid closed interval. If valid is an integer vector, x must also be an integer. valid can contain NA. For example, c(1, NA) means x must be no less than 1.

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

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

Examples

x <- 3.3

check_interval(x, c(1, 5))

if (FALSE) {
check_interval(x, c(1L, 5L))
check_interval(x, c(4, NA))
check_interval(x, c(NA, 2))
}