View source: R/assert_create.R
assert_create | R Documentation |
This function creates an assertion function that can be used to check the
validity of an input.
All assertions provided with this package are created using either assert_create()
or assert_create_chain()
assert_create(func, default_error_msg = NULL)
func |
A function defining the assertion criteria. This function should
return a logical value ( |
default_error_msg |
A character string providing an error message in case
the assertion fails. Must be supplied if function
|
An assertion function.
#' # Create an assertion function that checks that a character string is all
# lower case
assert_character <- assert_create(
is.character,
"{arg_name} must be a character vector, not a {class(arg_value)}"
)
# Use the assertion function
try({
is_lower("hello") # Returns invisible TRUE
is_lower("Hello") # Aborts the function with the error message
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.