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

Drop-in replacement for grep #129

Closed
Robinlovelace opened this Issue Sep 20, 2016 · 5 comments

Comments

Projects
None yet
3 participants
@Robinlovelace

Robinlovelace commented Sep 20, 2016

I assume there's a good reason why this seems not to have been done. However, I can't see it and think it would make it easier for people used to base regex to switch. str_which() could be a good option. Could put in a PR but wanted to check if this is something that would be useful.

grep("z", letters)
## [1] 26
 which(str_detect(letters, "z"))
## [1] 26

Context:

http://stackoverflow.com/questions/37996050/stringr-equivalent-to-grep/38012671?noredirect=1#comment66496080_38012671

csgillespie/efficientR@53c9643

@hadley

This comment has been minimized.

Member

hadley commented Dec 30, 2016

Why do you want indices though? I think it's usually a mistake to want them, and in general, you're better off making it explicit by using which (although str_which() might possible be a good name)

@hadley

This comment has been minimized.

Member

hadley commented Dec 30, 2016

@gagolews there's no existing equivalent of this in stringi, right?

@Robinlovelace

This comment has been minimized.

Robinlovelace commented Dec 30, 2016

Just for ease of use on the UI - many people discover grep() before they discover grepl() (based on my own experience and teaching). So I think a drop-in replacement would be used, especially by beginners. Just a use-ability thing and totally agree non indexed version is generally better.

@gagolews

This comment has been minimized.

Contributor

gagolews commented Dec 30, 2016

@hadley it's on a to-do list, gagolews/stringi#90

@hadley hadley closed this in 047df56 Jan 2, 2017

@Robinlovelace

This comment has been minimized.

Robinlovelace commented Jan 3, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment