extract_match1_conc_search: first match from 'pattern_conc_search'

Description Usage Arguments Examples

View source: R/conc_search.R

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

1
2
3
4
5
6
7
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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/dm documentation built on Jan. 18, 2022, 9:50 a.m.