assertive.strings (version 0.0-3)

assert_all_are_matching_fixed: Does the string match a pattern?

Description

Checks to see if in the input matches a regular expression or fixed character pattern.

Usage

assert_all_are_matching_fixed(x, pattern, opts_fixed = NULL, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_any_are_matching_fixed(x, pattern, opts_fixed = NULL, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_all_are_not_matching_fixed(x, pattern, opts_fixed = NULL, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_any_are_not_matching_fixed(x, pattern, opts_fixed = NULL, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_all_are_matching_regex(x, pattern, opts_regex = NULL, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_any_are_matching_regex(x, pattern, opts_regex = NULL, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_all_are_not_matching_regex(x, pattern, opts_regex = NULL, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_any_are_not_matching_regex(x, pattern, opts_regex = NULL, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
is_matching_fixed(x, pattern, opts_fixed = NULL, .xname = get_name_in_parent(x))
is_not_matching_fixed(x, pattern, opts_fixed = NULL, .xname = get_name_in_parent(x))
is_matching_regex(x, pattern, opts_regex = NULL, .xname = get_name_in_parent(x))
is_not_matching_regex(x, pattern, opts_regex = NULL, .xname = get_name_in_parent(x))

Arguments

x
string
pattern
pattern
opts_fixed
na_ignore
should NAs be ignored or not?
severity
How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".
opts_regex
.xname
Not intended to be used directly.

See Also

stri_detect, on which these functions are based.

Examples

Run this code
# Is it safe to eat oysters?
is_matching_fixed(month.name, "r")

# Sometimes it is easier to specify the negative match.
is_matching_regex(LETTERS, "[^AEIOU]")
is_not_matching_regex(LETTERS, "[AEIOU]")

# Matching is vectorized over both x and pattern
(pi_digits <- strsplit(format(pi, digits = 17), "")[[1]])
is_matching_regex(pi_digits, c("[13]", "[59]"))

assert_any_are_matching_regex(pi_digits, c("[13]", "[59]"))

# These checks should fail
assertive.base::dont_stop({
  assert_all_are_matching_regex(pi_digits, c("[13]", "[59]"))
})

Run the code above in your browser using DataCamp Workspace