`def` is the main utility of this package. It allows users to define functions that perform argument checking when called.

def(.f, ...)

Arguments

.f

Function

...

Named arguments for the function

Value

A function that will check its arguments when called

Examples

# Check argument type succ <- def(x = "numeric", { x + 1 }) succ(1) # => 2
#> [1] 2
succ('a') # => error
#> Error in succ("a"): Errors were found when checking validity of arguments: #> x -> Is a: numeric
# Check if argument is in a set of possible values f1 <- def(x = list(TRUE, FALSE, NA, NULL), { x && !x }) # Check any condition on an argument f2 <- def(x = (~ . > 0 && . < 10), { x + 1 }) # Chain multiple checks f3 <- def(x = "character" %&% (~ length(grep("hi", .)) > 0), { paste(x, "world!") }) # Set default values f4 <- def(x = "numeric" %=% 0, { rep(TRUE, x) })