Skip to content
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

select_helpers accept character vector? #50

Closed
ruaridhw opened this issue Jan 21, 2018 · 1 comment · Fixed by #128
Closed

select_helpers accept character vector? #50

ruaridhw opened this issue Jan 21, 2018 · 1 comment · Fixed by #128
Labels
feature helpers

Comments

@ruaridhw
Copy link

@ruaridhw ruaridhw commented Jan 21, 2018

Possible feature request though this may contradict #49

Allow for natively passing a vector of strings to starts_with, ends_with, contains ... in order to avoid having to redefine the regex

Currently:
(1) Unwieldy manual list of single columns

select(df,
       starts_with("a"),
       starts_with("b"),
       ends_with("c"),
       ends_with("d"),
       ...)

or

(2) Redefine matching regex for each select_helper

long_list_of_select_vars <- c("a", "b", ...)
another_long_vector <- c("c", "d", ...)
select(df,
       matches(paste0("^(", paste(long_list_of_select_vars, collapse="|"), ")")),
       matches(paste0("(", paste(another_long_vector, collapse="|"), ")$")))

Request:

select(df,
       starts_with(c("a", "b")),
       ends_with(c("c", "d")),
       ...)

which would have the same behaviour as (1)

For context

@huftis
Copy link

@huftis huftis commented Feb 14, 2018

The PR at tidyverse/dplyr#2958 (never commited) changed the semantics so that:

Selecting verbs (e.g. `select()` or verbs supporting `vars()`
selections) now treat symbols a bit differently. Symbols are only
evaluated in the data context, never in the calling context (#2904).
This means that you can no longer refer to local variables unless
you are explicitly unquoting these variables with `!!`.

Note that since last version, helper calls (like `starts_with()`)
obey the opposite behaviour and are evaluated in the calling
context, not the data context. To sum up, symbols can only refer to
data frame objects, while helpers can only refer to contextual
objects.

(Source: tidyverse/dplyr@331ed4e)

As long as it’s documented, that sounds like a reasonable behaviour, IMHO.

@lionel- lionel- added helpers feature labels Sep 9, 2019
lionel- added a commit to lionel-/tidyselect that referenced this issue Oct 18, 2019
lionel- added a commit to lionel-/tidyselect that referenced this issue Oct 18, 2019
lionel- added a commit to lionel-/tidyselect that referenced this issue Oct 18, 2019
lionel- added a commit to lionel-/tidyselect that referenced this issue Oct 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature helpers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants