powered by
This function asserts that the input is not NULL and aborts with an error message if it is.
assert_non_null(x, msg = NULL, call = rlang::caller_env(), arg_name = NULL)
invisible(TRUE) if x is not NULL, otherwise aborts with the error message specified by msg.
x
msg
A value to check.
A character string containing the error message to display if x is NULL.
Only relevant when pooling assertions into multi-assertion helper functions. See cli_abort for details.
Advanced use only. Name of the argument passed (default: NULL, will automatically extract arg_name).
# Passes for non-NULL assert_non_null(1) try({ # Throws default error for NULL assert_non_null(NULL) # Throws custom error message assert_non_null(NULL, msg = "Custom error message") })
Run the code above in your browser using DataLab