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

stri_(any|all)_(regex|fixed) #488

Closed
bhagwataditya opened this issue Feb 2, 2023 · 1 comment
Closed

stri_(any|all)_(regex|fixed) #488

bhagwataditya opened this issue Feb 2, 2023 · 1 comment

Comments

@bhagwataditya
Copy link

bhagwataditya commented Feb 2, 2023

Thankyou very much for wonderful stringi :)
Right now I am doing this:

#' Does any string have a regex
#' @param str      string vector
#' @param pattern  string
#' @return TRUE or FALSE
#' @examples 
#' str <- c('s1 Spectral Count', 's1 Unique Spectral Count')
#' patterns <- c('Spectral Count', '(?<!Unique) Spectral Count', 'Intensity')
#' stri_detect_regex(str, pattern = patterns[1])
#' stri_detect_regex(str, pattern = patterns[2])
#' stri_detect_regex(str, pattern = patterns[3])
#' stri_any_regex(   str, pattern = patterns)
#' @export
.stri_any_regex <- function(str, pattern) any(stri_detect_regex(str, pattern))

stri_any_regex <- function(str, pattern){
    vapply(pattern, function(pat) .stri_any_regex(str, pat), logical(1))
}

Something like this of interest to be had within stringi?

@bhagwataditya bhagwataditya changed the title stri_any_regex and stri_all_regex stri_(any|all)_(regex|fixed) Feb 2, 2023
@bhagwataditya bhagwataditya reopened this Feb 2, 2023
@gagolews
Copy link
Owner

gagolews commented Feb 2, 2023

Thanks, but as you can see, this is easily achievable with 2-3 function calls, therefore no need to make the stringi API more bloated than it already is...

Alternatives:

  1. use outer+apply
  2. use a regex like pat1|pat2|pat3 - should be the fastest

@gagolews gagolews closed this as completed Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants