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

specifying fixed=TRUE to contains() within select() #608

Closed
thelatemail opened this issue Sep 18, 2014 · 4 comments
Closed

specifying fixed=TRUE to contains() within select() #608

thelatemail opened this issue Sep 18, 2014 · 4 comments
Assignees
Labels
Milestone

Comments

@thelatemail
Copy link

@thelatemail thelatemail commented Sep 18, 2014

When using select + contains, there doesn't appear to be a way to specify searching for a fixed string, instead of a an interpreted regular expression pattern. E.g.:

select(iris, contains(".") ) # also returns "Species" column

This seems at odds with the docs: "selects all variables whose name contains ‘x’"

Neither of the below work, as an intuitive guess at passing the argument:

select(iris, contains(".", fixed=TRUE) )
select(iris, contains("."), fixed=TRUE )

My gut feeling would be that contains() should be fixed=TRUE by default, and matches() fixed=FALSE by default, as it is for base grep() etc.

External reference:
http://stackoverflow.com/questions/25923392/r-dplyr-select-columns-based-on-string#comment40580632_25923466

@thelatemail
Copy link
Author

@thelatemail thelatemail commented Sep 19, 2014

Apologies, this is a duplicate of joran's #607
I didn't realise we were both writing at the same time.

@hadley hadley added bug feature and removed bug labels Sep 22, 2014
@hadley hadley added this to the 0.3 milestone Sep 22, 2014
@hadley hadley self-assigned this Sep 22, 2014
@hadley hadley closed this in a4c31de Sep 22, 2014
@eipi10
Copy link
Contributor

@eipi10 eipi10 commented Oct 8, 2014

I just ran into an issue where I was using contains with a regex that worked find a couple of months ago, but now with fixed=TRUE as the default, the regex no longer works (in fact it doesn't match anything in this case). I tried passing fixed=FALSE, but contains doesn't recognize it and throws an error. Is that a bug, or is there some other, more dplyr-ish way that I should be selecting columns based on a regex? For reference, here's the code I was running. It's the same as my previous code, but with fixed=FALSE added:

erss %>% 
    select(contains("emplid|elm|entry|enrollment|level|term$", fixed=FALSE))
Error in contains(vars, ...) : unused argument (fixed = FALSE)

I know I could just type out the variable names, but there are a lot of them and I'm trying to avoid having to do that.

@hadley
Copy link
Member

@hadley hadley commented Oct 8, 2014

Use matches()

@eipi10
Copy link
Contributor

@eipi10 eipi10 commented Oct 8, 2014

Great. Thanks Hadley!

@lock lock bot locked as resolved and limited conversation to collaborators Jun 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants