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

Fail early when empty pattern is provided to select_vars #481

Merged
merged 2 commits into from Aug 1, 2014

Conversation

@leondutoit
Copy link
Contributor

@leondutoit leondutoit commented Jul 1, 2014

The current default behaviour of select_vars, with sub
functions starts_with, ends_with, contains and
matches, when provided with a character pattern of
length zero, is to return all columns of the tbl. This commit
changes that default behaviour: now these functions fail
early, selecting nothing and telling the user that
an empty pattern was provided.

The current default behaviour of select_vars, with sub
functions `starts_with`, `ends_with`, `contains` and
`matches`, when provided with a character pattern of
length zero, is to return all columns of the tbl. This commit
changes that default behaviour: now these functions fail
early, selecting nothing and telling the user that
an empty pattern was provided.
@leondutoit
Copy link
Contributor Author

@leondutoit leondutoit commented Jul 1, 2014

The default behaviour of select_vars in these cases is obviously a design decision, but as a user of the library I would rather have selection with an empty pattern match fail and tell me about it.

The pull request provides an implementation of the changed behaviour and tests to cover the cases. Now doing tbl %>% select(starts_with('')) will fail instead of returning all columns. The same goes for other select functions that use pattern matching.

There is also a bug related to select_vars where all columns are returned instead of none when there is no match found, but I will propose a change in a different patch...

Feel free to merge if you agree with the proposed change :)

@hadley
Copy link
Member

@hadley hadley commented Jul 28, 2014

Thanks! Could you please add a bullet point to NEWS.md, mentioning the issue and your github username?

@leondutoit
Copy link
Contributor Author

@leondutoit leondutoit commented Jul 30, 2014

Done.

@leondutoit
Copy link
Contributor Author

@leondutoit leondutoit commented Jul 30, 2014

oh the build failed with a strange error, maybe it needs a re-trigger... I don't have the permissions to do that.

@romainfrancois
Copy link
Member

@romainfrancois romainfrancois commented Jul 30, 2014

just restarted the build.

hadley added a commit that referenced this issue Aug 1, 2014
Fail early when empty pattern is provided to select_vars
@hadley hadley merged commit db05bfa into tidyverse:master Aug 1, 2014
1 check passed
@hadley
Copy link
Member

@hadley hadley commented Aug 1, 2014

Thanks!

krlmlr pushed a commit to krlmlr/dplyr that referenced this issue Mar 2, 2016
Fail early when empty pattern is provided to select_vars
@lock
Copy link

@lock lock bot commented Jan 19, 2019

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/

@lock lock bot locked and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants