FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

FR: Allow `patterns` to have the arguments of `grep` · Issue #5387 · Rdatatable/data.table · GitHub

FR: Allow patterns to have the arguments of grep #5387

Description

Beyond the 2 essential arguments of grep, most of the other would be also useful if they were included in patterns. In fact, any other except value could help to look for much other patterns.

In particular, it is needed for certain #regex which only work under perl=TRUE.

So I propose to modify

patterns = function(..., cols=character(0L)) {
  # if ... has no names, names(list(...)) will be "";
  #   this assures they'll be NULL instead
  L = list(...)
  p = unlist(L, use.names = any(nzchar(names(L))))
  if (!is.character(p))
    stopf("Input patterns must be of type character.")
  matched = lapply(p, grep, cols)
  # replace with lengths when R 3.2.0 dependency arrives
  if (length(idx <- which(sapply(matched, length) == 0L)))
    stopf('Pattern(s) not found: [%s]', brackify(p[idx]))
  matched
}

with something like

patterns = function(..., cols=character(0L), ignore.case = FALSE, perl = FALSE, fixed = FALSE, useBytes = FALSE, invert = FALSE) {
  # if ... has no names, names(list(...)) will be "";
  #   this assures they'll be NULL instead
  L = list(...)
  p = unlist(L, use.names = any(nzchar(names(L))))
  if (!is.character(p))
    stopf("Input patterns must be of type character.")
  matched = lapply(p, grep, cols, ignore.case = ignore.case, perl = perl, fixed = fixed, useBytes = useBytes, invert = invert)
  # replace with lengths when R 3.2.0 dependency arrives
  if (length(idx <- which(sapply(matched, length) == 0L)))
    stopf('Pattern(s) not found: [%s]', brackify(p[idx]))
  matched
}

Thanks!

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL