strExtract: Extract first pattern occurance

View source: R/strExtract.R

strExtractR Documentation

Extract first pattern occurance

Description

Uses regexpr() internally without regmatches().

Usage

strExtract(x, pattern, fixed = FALSE)

Arguments

x

character. Character vector. NA values are allowed.

pattern

character(1). Regular expression pattern. Evalutes with regexpr() internally.

fixed

logical(1). If TRUE, pattern is a string to be matched as is. Otherwise, will match by regular expression.

Details

Expands with NA values for match failures, like stringi and stringr.

Value

character. Character vector of matches. Failures return NA.

Note

Updated 2023-09-25.

See Also

  • regexpr(), regmatches().

  • stringi::stri_extract_first().

  • stringr::str_extract().

  • https://stringr.tidyverse.org/articles/from-base.html

Examples

object <- strExtract(
    x = c("apples x10", "bag of flour", "bag of sugar", "milk x200", NA),
    pattern = "\\d+"
)
print(object)

acidgenomics/acidbase documentation built on Jan. 26, 2024, 4:26 p.m.