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
Support more advanced patterns in matches() #3209
Comments
|
Until this most recent release of the tidyverse package, stringr hadn't been part of the "core" (i.e. wasn't attached unless loaded separately from tidyverse). There's also the dependency factor. |
|
Hi, looking at the source code, Here is demo codes for illustration of all this reprex::reprex_info()
#> Created by the reprex package v0.1.1.9000 on 2017-11-17
library(dplyr, warn.conflicts = F)
test <- tibble(
hh15_test = c(1,2,3),
hh02_test = c(3,3,3),
hh3_test=c(4,4,5),
blah = c(1,2,3)
)
test
#> # A tibble: 3 x 4
#> hh15_test hh02_test hh3_test blah
#> <dbl> <dbl> <dbl> <dbl>
#> 1 1 3 4 1
#> 2 2 3 4 2
#> 3 3 3 5 3
# does not recognized
select(test, matches("(hh1)|^(?!hh)"))
#> Error in grep(needle, haystack, ...): expression régulière '(hh1)|^(?!hh)' incorrecte, à cause de 'Invalid regexp'
# does not recognized either
grep("(hh1)|^(?!hh)", names(test))
#> Error in grep("(hh1)|^(?!hh)", names(test)): expression régulière '(hh1)|^(?!hh)' incorrecte, à cause de 'Invalid regexp'
# It is recognized now
grep("(hh1)|^(?!hh)", names(test), perl = T)
#> [1] 1 4
# stringr recognizes it too
stringr::str_subset(names(test), "(hh1)|^(?!hh)")
#> [1] "hh15_test" "blah"At last, you said that this works In conclusion, your issue raises a question about which flavors |
|
Thanks for the digging @cderv. You've also spotted a bug in my simplified reproduction. The second case was actually throwing an error too. It's working now in the second case as expected. |
|
@hadley: What flavor of regular expressions should we accept in |
|
Moving this to r-lib/tidyselect#58 as matches was factored out of dplyr. |
|
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
I tried to use matches() to match a slightly complex regular expression but it didn't support it so I had to use stringr instead. It seems that matches() uses grep rather than stringr.
The text was updated successfully, but these errors were encountered: