R/filter_element.R

Defines functions filter_element

Documented in filter_element

#' Remove Elements in a Vetor
#' 
#' Removes the matching elements of a vector.
#' 
#' @param x A character vector.
#' @param pattern A regex pattern to match for exclusion.
#' @param \ldots Other arguments passed to \code{\link[base]{grep}}.
#' @return Returns a vector with matching elements removed.
#' @export
#' @examples 
#' x <- c('dog', 'cat', 'bat', 'dingo', 'dragon', 'dino')
#' filter_element(x, '^d.+?g')
#' filter_element(x, 'at$')
#' filter_element(x, '^d')
#' filter_element(x, '\\b(dog|cat)\\b')
filter_element <- function(x, pattern, ...){
    
    warning(
        paste(
            "Deprecated, use textclean::drop_elements() instead.",
            "`filter_element()` will be removed in the next version."
        ),
        call. = FALSE
    )
    
    grep(pattern, x, value =  TRUE, invert = TRUE, perl = TRUE, ...)
}
trinker/textmod documentation built on Dec. 10, 2018, 11:26 p.m.