predicates-pattern: Pattern predicates

Description Usage Arguments Details See Also Examples

Description

Pattern predicates

Usage

1
2
3
4
5
chk_grepl(x, pattern, ignore.case = FALSE, perl = FALSE)

chk_starts_with(x, prefix, na.rm = FALSE)

chk_ends_with(x, suffix, na.rm = FALSE)

Arguments

x

Object to test.

pattern

Regular expression.

ignore.case

Should pattern matching ignore case?

perl

Should Perl-compatible regular expressions be used?

prefix, suffix

String to match.

na.rm

Should NA values be disregarded?

Details

To maintain consistency with grepl(), chk_starts_with() and chk_ends_with() coerce to character before matching.

See Also

grepl(), startsWith(), endsWith()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
ymd <- function(y, m, d) paste(y, m, d, sep = "/")

too_old <- "Not a 21st-century year"
recent_ymd <- firmly(ymd, !! too_old := chk_grepl("^20[[:digit:]]{2}$", y))

recent_ymd(2017, 01, 01)
## Not run: 
recent_ymd(1999, 01, 01)
## End(Not run)

way_too_old <- "Pre-2010 year is too old"
more_recent_ymd <- firmly(ymd, !! way_too_old := chk_starts_with("201", y))

more_recent_ymd(2017, 01, 01)
## Not run: 
more_recent_ymd(2001, 01, 01)
## End(Not run)

egnha/rong documentation built on May 7, 2019, 9:48 p.m.