check_patterns | R Documentation |
This helper function takes two character vectors mainstrs
and patterns
, returning a boolean indicating
whether each element of patterns
is a string pattern in which at least one element of mainstrs
starts with.
In other words, for each element of patterns
, does any element of mainstrs
start with this particular pattern?
If so, return TRUE
. This helper can be used to efficiently verify the argument patterns
in split_df()
,
especially when there is a large number of patterns.
check_patterns(mainstrs, patterns)
mainstrs |
A character vector of strings that are checked against each element in |
patterns |
A character vector of pattern strings. |
A logical vector with the same length as patterns
, indicating whether each pattern is one that
at least one string in mainstrs
starts with.
# Vector of patterns patterns <- c("prefix_1", "predix_2", ...) # Checking if these patterns are valid for 'df' check_patterns(mainstrs = names(df), patterns) |> all() # Find all invalid patterns valid_index <- check_patterns(mainstrs = names(df), patterns) patterns[!valid_index]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.