| assert_all_strings_contain | R Documentation |
Assert all elements of a character vector match a regex pattern.
assert_all_strings_contain(
x,
pattern,
ignore.case = FALSE,
perl = FALSE,
fixed = FALSE,
useBytes = FALSE,
msg = NULL,
call = rlang::caller_env(),
arg_name = NULL
)
x |
An object to check |
pattern |
A regular expression pattern (string) |
ignore.case, perl, fixed, useBytes |
Logical flags passed to |
msg |
A character string containing the error message to display if |
call |
Only relevant when pooling assertions into multi-assertion helper functions. See cli_abort for details. |
arg_name |
Advanced use only. Name of the argument passed (default: NULL, will automatically extract arg_name). |
invisible(TRUE) if x matches pattern, otherwise aborts with the error message specified by msg
try({
assert_all_strings_contain(c("abc", "a1"), "^a") # Passes
assert_all_strings_contain(c("abc", "b1"), "^a") # Throws default error
assert_all_strings_contain(c("abc", "b1"), "^a", 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.