Skip to contents

Filters for records matching a given string.

Usage

remove_deletions(x, val = stringr::regex("Delete", ignore_case = TRUE))

Arguments

x

input vector

val

Character or regex. The value to check for inequality. Val is fed into stringr::str_detect as the pattern parameter. Defaults to 'Delete' with ignore case = TRUE. See stringr::str_detect for more details.

Value

logical vector

Details

To be used within dplyr::filter(). The function returns a logical vector with TRUE resulting from values that are not equal to the val argument. Also protects from NA values.

Used within verbs such as tidyselect::all_of() this can work effectively across all columns in a data frame. See examples

Examples

data <- data.frame("a" = sample(c("Delete", "Keep",NA),size = 10,replace = TRUE))

data |>
  dplyr::filter(dplyr::if_all(everything(), remove_deletions))
#>      a
#> 1 Keep
#> 2 <NA>
#> 3 <NA>
#> 4 <NA>
#> 5 Keep
#> 6 <NA>
#> 7 <NA>