assertions {ympes}R Documentation

Argument assertions

Description

Assertions for function arguments. Motivated by vctrs::vec_assert() but with lower overhead at a cost of less informative error messages. Designed to make it easy to identify the top level calling function whether used within a user facing function or internally.

Usage

assert_integer(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_int(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_double(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_dbl(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_numeric(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_num(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_logical(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_lgl(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_character(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_chr(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_data_frame(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_list(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_scalar_integer(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_scalar_int(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_scalar_double(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_scalar_dbl(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_scalar_numeric(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_scalar_num(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_scalar_logical(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_scalar_lgl(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_bool(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_boolean(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_scalar_character(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_scalar_chr(x, arg = deparse(substitute(x)), call = sys.call(-1L))

assert_string(x, arg = deparse(substitute(x)), call = sys.call(-1L))

Arguments

x

Argument to check.

arg

⁠[character]⁠

Name of argument being checked (used in error message).

call

⁠[call]⁠

Call to use in error message.

Value

NULL if the assertion succeeds (error otherwise).

Examples


# Use in a user facing function
fun <- function(i, d, l, chr, b) {
    assert_scalar_int(i)
    TRUE
}
fun(i=1L)
try(fun())
try(fun(i="cat"))

# Use in an internal function
internal_fun <- function(a) {
    assert_string(a, arg = deparse(substitute(a)), call = sys.call(-1L))
    TRUE
}
external_fun <- function(b) {
    internal_fun(a=b)
}
external_fun(b="cat")
try(external_fun())
try(external_fun(b = letters))


[Package ympes version 0.3.0 Index]