test_regex: Test Regex Validity

Description Usage Arguments Value Examples

View source: R/test_regex.R

Description

Test an atomic vector, list, or term list of regexes for validity.

Usage

1
test_regex(regex, stringi = TRUE, ...)

Arguments

regex

An atomic vector, list, or term list of regexes to test for validity.

stringi

logical. If TRUE stringi's implementation of reguar expressions is utilized for testing. This allows for more flexible use of regular expressions, otherwise base R is used for validation.

...

ignored.

Value

Returns x back with warnings. Note that if a list is passed it is coerced to a term_list.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
## Not run: 
## atomic vector
test_regex(c('.', 'a'))  ## works
test_regex(c('.', '(a')) ## warning

## list
test_regex(list(c('.', 'a'), 'd'))   ## works
test_regex(list(c('.', 'a(('), 'd')) ## warning

discoure_markers <- list(
    response_cries = c("\\boh", "\\bah", "\\baha", "\\bouch", "yuk"),
    back_channels = c("uh[- ]huh", "uhuh", "yeah"),
    summons = "hey",
    justification = "because"
)

trmlst_unnested <- read_term_list(term.list = discoure_markers, collapse = FALSE)
test_regex(trmlst_unnested) ## works
trmlst_unnested[[1]][1] <- 'bad1('
trmlst_unnested[[1]][3] <- 'bad2('
trmlst_unnested[[3]][1] <- 'bad3('
test_regex(trmlst_unnested) ## warning

trpl_list <- list(
    list(
        response_cries = c("\\boh", "\\bah", "\\baha", "\\bouch", "yuk"),
        back_channels = c("uh[- ]huh", "uhuh", "yeah"),
        summons = "hey",
        justification = "because"
    ),
    list(summons ='the'),
    list(summons = 'it', justification = 'ed\\s')
)

trmlst_nested <- read_term_list(term.list = trpl_list, collapse = FALSE)
test_regex(trmlst_nested) ## works
trmlst_nested[[1]][[1]][1] <- 'bad1('
trmlst_nested[[1]][[1]][3] <- 'bad2('
trmlst_nested[[1]][[3]][1] <- 'bad3('
trmlst_nested[[3]][[1]][1] <- 'bad4('
test_regex(trmlst_nested) ## warning


## End(Not run)

trinker/termco documentation built on Jan. 7, 2022, 3:32 a.m.