R/utils.R

Defines functions str_remove_all str_replace_all str_detect

str_detect <- function(string, pattern) {
  grepl(pattern = pattern, x = string, perl = TRUE)
}

str_replace_all <- function(string, pattern, replacement) {
  if (!is.null(names(pattern))) {
    for (i in seq_along(pattern)) {
      string <- gsub(
        pattern = names(pattern)[[i]],
        replacement = pattern[[i]],
        x = string,
        perl = TRUE
      )
    }

    return(string)
  }

  gsub(pattern = pattern, replacement = replacement, x = string, perl = TRUE)
}

str_remove_all <- function(string, pattern) {
  gsub(pattern = pattern, replacement = "", x = string, perl = TRUE)
}

Try the nombre package in your browser

Any scripts or data that you put into this service are public.

nombre documentation built on May 23, 2022, 5:06 p.m.