Skip to content

FR: resolve incompatible pattern modification earlier #60

@ctbrown

Description

@ctbrown

Please have incompatible search modifiers fixed vs perl / ignore.case be resolved at the call of these function and not defer to the str_* calls. Take the following example:

pattern <- 
  "str" %>%
  ignore.case %>%
  perl  # %>%
  # fixed -> pattern


str(pattern)
# Overriding Perl regexp matching
#  atomic [1:1] pattern
#  - attr(*, "ignore.case")= logi TRUE
#  - attr(*, "perl")= logi TRUE
#  - attr(*, "fixed")= logi TRUE

In this case, each of the match modifiers set an attribute to TRUE, though they are incompatible. If one were to examine pattern as is done in the example, the effects are unclear as they will be resolved later. A better method would have successive calls to the modifiers adjust pattern as appropriate. This can be done changing the functions. For example, fixed might become:

fixed <-   function(string) {
  if (stringr::is.perl(string)) 
    message("Overriding Perl regexp matching")
  structure(string, fixed = TRUE, perl = NULL, ignore.case = NULL )
}

Or perl = FALSE as another alternative.

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