assert | R Documentation |
Assert that conditions are met
assert(..., msg = NULL, call = rlang::caller_env())
... |
a list of conditions to check |
msg |
A character string containing the error message to display if any of the conditions are not met. The string can include the placeholder {failed_expressions} to insert a list of the failed expressions. The string can also include {?s} and {?is/are} to insert the correct pluralization for the list of failed expressions. |
call |
Only relevant when pooling assertions into multi-assertion helper functions. See cli_abort for details. |
invisible(TRUE) if all conditions are met, otherwise aborts with the error message specified by msg
try({
assert(1 == 1) # Passes
assert(2 == 2, 3 == 3) # Passes
assert(2 == 1, 3 == 3) # Throws default error
assert(2 == 1, 3 == 3, msg = "Custom error message") # Throws custom error
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.