Skip to contents

Checks if an argument is a numeric vector

Usage

assert_numeric_vector(arg, optional = FALSE)

Arguments

arg

A function argument to be checked

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 numeric vector. Otherwise, the input is returned invisibly.

Examples

example_fun <- function(num) {
  assert_numeric_vector(num)
}

example_fun(1:10)

try(example_fun(letters))
#> Error in assert_numeric_vector(num) : 
#>   `num` must be a numeric vector but is a character vector