R/str_detect_fixed_all.R

Defines functions str_detect_fixed_all

Documented in str_detect_fixed_all

#' Returns a logical vector with results of stri_detect() for each pattern in
#' second parameters character vector.
#'
#' @usage str_detect_fixed_all(strings, patterns, ignore_na, ...)
#' @param strings input vector. This must be an atomic vector and will be
#' coerced to a character vector.
#' @param patterns patterns to look for, as defined by a POSIX regular
#' expression. See fixed, ignore.case and perl sections
#' for details. See  \emph{Extended Regular Expressions} for how to use regular
#' expressions for matching.
#' @param ignore_na if TRUE NA values are trimmed out of \code{strings} and 
#' \code{patterns} before comparison
#' @param ... further arguments for stri_detect_fixed
#' @import stringi
#' @export
str_detect_fixed_all <- function(strings, patterns, ignore_na = FALSE, ...) {
  if (ignore_na) {
    strings <- strings[!is.na(strings)]
    patterns <- patterns[!is.na(patterns)]
  }
  vapply(patterns, function(pattern) {
    any(stri_detect_fixed(strings, pattern, ...))}, logical(1))
}
rmsharp/rmsutilityr documentation built on Feb. 13, 2024, 6:01 p.m.