stri_subset {stringi} | R Documentation

## Select Elements that Match a Given Pattern

### Description

These functions return 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, ...)]`.

### Usage

    stri_subset(str, ..., regex, fixed, coll, charclass)

    stri_subset_fixed(str, pattern, omit_na = FALSE, ..., opts_fixed = NULL)

    stri_subset_charclass(str, pattern, omit_na = FALSE)

    stri_subset_coll(str, pattern, omit_na = FALSE, ..., opts_collator = NULL)

    stri_subset_regex(str, pattern, omit_na = FALSE, ..., opts_regex = NULL)

### Arguments

`str` | 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
`pattern,regex,fixed,coll,charclass` | character vector defining search patterns; for more details refer to stringi-search
`omit_na` | single logical value; should missing values be excluded from the result?
`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;

### Details

Vectorized over `str` and `pattern`. Of course, normally you will use that function in case of `length(str) >= length(pattern)`.

`stri_subset` is a convenience function. It calls either `stri_subset_regex`, `stri_subset_fixed`, `stri_subset_coll`, or `stri_subset_charclass`, depending on the argument used. Relying on those underlying functions will make your code run slightly faster.

### Value

All the functions return a character vector. As usual, the output encoding is always UTF-8.

### See Also

Other search_subset: `stringi-search`

### Examples

    stri_subset_fixed(c("stringi R", "REXAMINE", "123"), c('i', 'R', '0'))
    stri_subset_fixed(c("stringi R", "REXAMINE", "123"), 'R')
    stri_subset_charclass(c("stRRRingi","REXAMINE","123"),
       c("\\p{Ll}", "\\p{Lu}", "\\p{Zs}"))

[Package stringi version 1.0-1 Index]