R/remove_phrase_from_string.R

Defines functions remove_phrase_from_string

Documented in remove_phrase_from_string

#' Removes a pharse from a string
#' @param string character vector of length 1
#' @param phrase character vector of length 1 to be removed from string
#' @importFrom stringr str_replace_all
#' @export
#' 
remove_phrase_from_string <-
        function(string, phrase) {
                p <- paste0("(.*\\s{0,1})(", phrase, ")(\\s{0,1}.*)")
                stringr::str_replace_all(gsub(p, paste0("\\1 \\3"), string), " {2,}", " ")
        }
patelm9/caterpillaR documentation built on Nov. 20, 2019, 10:41 a.m.