extract_match1_conc_search: first match from 'pattern_conc_search'

View source: R/conc_search.R

extract_match1_conc_searchR Documentation

Description

use pattern_conc_search but also extract the match from within the concatenation. Note to self: the use of pattern_conc_search is superfluous within this function as it applies searches to the string which is split at the code.sep, but makes it easier to use search terms defined as variables

Usage

extract_match1_conc_search(
  x,
  s,
  code.sep = " ",
  reduce = FALSE,
  s.fixed = FALSE
)

Arguments

x

(concatenated) search string

s

string to match initial part of code

code.sep

the string that servers as separator in the concatenation

reduce

if FALSE, always return string of same length as x

s.fixed

set to TRUE if 's' was created by pattern_conc_search

Examples

x <- c("ABC", "", "FFF XXX", "GGG  ABC FOO",
       "BAR  ABC", "FOO BAR ABB", " ", ";")
s.term = c("AB(C|B)", "X")
## extract only the (first) matches
extract_match1_conc_search(x, s = s.term, reduce = TRUE)
## extract but do not reduce:
data.frame(x = x,
           extr.m1 = extract_match1_conc_search(x, s = s.term,
                                                reduce = FALSE))
## same example, different separator:
y <- gsub(pattern = " ", replacement = ";", x)
data.frame(y = y,
           extr = extract_match1_conc_search(y, s = s.term,
                                             code.sep = ";", reduce = FALSE))

renlund/datma documentation built on June 2, 2025, 5:12 a.m.