Select Elements that Match a Given Pattern

These functions return or modify a subvector consisting of strings that match a given pattern. In other words, they are roughly equivalent (but faster and easier to use) to a call to str[stri_detect(str, ...)] or str[stri_detect(str, ...)] <- value<="" code="">.

stri_subset(str, ..., regex, fixed, coll, charclass)
stri_subset(str, ..., regex, fixed, coll, charclass) <- value<="" div="">
stri_subset_fixed(str, pattern, omit_na = FALSE, negate = FALSE, ..., opts_fixed = NULL)
stri_subset_fixed(str, pattern, negate=FALSE, ..., opts_fixed=NULL) <- value<="" div="">
stri_subset_charclass(str, pattern, omit_na = FALSE, negate = FALSE)
stri_subset_charclass(str, pattern, negate=FALSE) <- value<="" div="">
stri_subset_coll(str, pattern, omit_na = FALSE, negate = FALSE, ..., opts_collator = NULL)
stri_subset_coll(str, pattern, negate=FALSE, ..., opts_collator=NULL) <- value<="" div="">
stri_subset_regex(str, pattern, omit_na = FALSE, negate = FALSE, ..., opts_regex = NULL)
stri_subset_regex(str, pattern, negate=FALSE, ..., opts_regex=NULL) <- value<="" div="">
character vector with strings to search in
supplementary arguments passed to the underlying functions, including additional settings for opts_collator, opts_regex, opts_fixed, and so on
character vector to be substituted with; replacement function only
pattern, regex, fixed, coll, charclass
character vector defining search patterns; for more details refer to stringi-search; the replacement functions accept only one pattern at a time
single logical value; should missing values be excluded from the result?
single logical value; whether a no-match is rather of interest
opts_collator, opts_fixed, opts_regex
a named list used to tune up a search engine's settings; see stri_opts_collator, stri_opts_fixed, and stri_opts_regex, respectively; NULL for default settings;

Vectorized over str, and pattern or value (replacement version).
stri_subset and stri_subset<-< code=""> are convenience functions. They call either stri_subset_regex, stri_subset_fixed, stri_subset_coll, or stri_subset_charclass, depending on the argument used. Relying on these underlying functions will make your code run slightly faster.


The stri_subset functions return a character vector. As usual, the output encoding is always UTF-8.The stri_subset<-< code=""> functions change the str object.

See Also

Other search_subset: stringi-search

  • stri_subset
  • stri_subset<-
  • stri_subset_charclass
  • stri_subset_charclass<-
  • stri_subset_coll
  • stri_subset_coll<-
  • stri_subset_fixed
  • stri_subset_fixed<-
  • stri_subset_regex
  • stri_subset_regex<-
library(stringi) stri_subset_regex(c("stringi R", "123", "ID456", ""), "^[0-9]+$") x <- c("stringi R", "123", "ID456", "") stri_subset_regex(x, "[^0-9]+|^$") <- NA print(x) x <- c("stringi R", "123", "ID456", "") stri_subset_regex(x, "^[0-9]+$", negate=TRUE) <- NA print(x)
Documentation reproduced from package stringi, version 1.1.2, License: file LICENSE

Community examples

Looks like there are no examples yet.