Skip to content

Commit

Permalink
[fix r-lib#71] add perl argument to matches()
Browse files Browse the repository at this point in the history
  • Loading branch information
fmichonneau committed Jul 8, 2019
1 parent 013a51a commit 66ae548
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Expand Up @@ -3,6 +3,8 @@

* `vars_select()` ignores vectors with only zeros (#82).

* `matches()` has new argument `perl` to allow for Perl-like regular expressions (requested by @GegznaV, #71)

# tidyselect 0.2.5

This is a maintenance release for compatibility with rlang 0.3.0.
Expand Down
5 changes: 3 additions & 2 deletions R/select-helpers.R
Expand Up @@ -13,6 +13,7 @@
#' @param match A string.
#' @param ignore.case If `TRUE`, the default, ignores case when matching
#' names.
#' @param perl Should Perl-compatible regexps be used?
#' @param vars,.vars A character vector of variable names. When called
#' from inside selecting functions like [dplyr::select()] these are
#' automatically set to the names of the table.
Expand Down Expand Up @@ -73,10 +74,10 @@ contains <- function(match, ignore.case = TRUE, vars = peek_vars()) {

#' @export
#' @rdname select_helpers
matches <- function(match, ignore.case = TRUE, vars = peek_vars()) {
matches <- function(match, ignore.case = TRUE, perl = FALSE, vars = peek_vars()) {
stopifnot(is_string(match), nchar(match) > 0)

grep_vars(match, vars, ignore.case = ignore.case)
grep_vars(match, vars, ignore.case = ignore.case, perl = perl)
}

#' @export
Expand Down
4 changes: 3 additions & 1 deletion man/select_helpers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/testthat/test-select-helpers.R
Expand Up @@ -22,6 +22,7 @@ test_that("matches return integer positions", {
expect_equal(ends_with("d"), c(2L, 4L))
expect_equal(contains("eee"), 5L)
expect_equal(matches(".b."), c(1L, 3L, 4L))
expect_equal(matches("(?<!a)b", perl = TRUE), c(3L, 4L))
})

test_that("throws with empty pattern is provided", {
Expand Down

0 comments on commit 66ae548

Please sign in to comment.