New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add negate argument to str_subset(), str_detect(), and str_which() #259

merged 5 commits into from Jan 4, 2019


None yet
2 participants
Copy link

yutannihilation commented Oct 1, 2018

Currently, there's no cool way of doing grep -v with stringr. If I want to negate the pattern, I need to use str_detect(), but this is not handy.


fruit <- c("apple", "banana", "pear", "pinapple")
fruit[!str_detect(fruit, "^p)]

On the other hand, stringi's equivalent functions have negate argument since version 1.1.1. So, it seems easy to introduce the argument in stringr package. Note that my primary motivation was str_subset(), only, but as stringi::stri_detect() also has negate, I included the equivalent functions, str_detect() and str_which().


fruit <- c("apple", "banana", "pear", "pinapple")
str_subset(fruit, "^p")
#> [1] "pear"     "pinapple"

str_subset(fruit, "^p", negate = TRUE)
#> [1] "apple"  "banana"

Created on 2018-10-01 by the reprex package (v0.2.1)

@hadley hadley merged commit 5177959 into tidyverse:master Jan 4, 2019

3 of 4 checks passed

codecov/patch 55.55% of diff hit (target 89.23%)
codecov/project 89.51% (+0.28%) compared to 0b5a4c4
continuous-integration/appveyor/pr AppVeyor build succeeded
continuous-integration/travis-ci/pr The Travis CI build passed

This comment has been minimized.

Copy link

hadley commented Jan 4, 2019


@yutannihilation yutannihilation deleted the yutannihilation:add-negate-arg branch Jan 4, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment