Skip to content

Drop-in replacement for grep #129

Closed
Closed

Description

@Robinlovelace

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

Activity

  1. hadley commented on Dec 30, 2016

    @hadley
    Member

    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)

  2. hadley commented on Dec 30, 2016

    @hadley
    Member

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

  3. Robinlovelace commented on Dec 30, 2016

    @Robinlovelace
    Author

    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.

  4. gagolews commented on Dec 30, 2016

    @gagolews
    Contributor

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

  5. Robinlovelace commented on Jan 3, 2017

    @Robinlovelace
    Author

    Thanks!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions