s_regex {tinycodet}R Documentation

Pattern Specifications for String Related Infix Operators

Description

The %s-% and %s/% operators, as well as the string detection operators (str_truth), perform pattern matching for some purpose, where the pattern is given on the right hand side.
When a character vector or string is given on the right hand side, this is interpreted as case-sensitive regex patterns from 'stringi'.

Instead of giving a string or character vector of regex patterns, one can also supply a list to specify exactly how the pattern should be interpreted. The list should use the exact same argument convention as 'stringi'.

For example:

All arguments in the list are simply passed to the appropriate functions in 'stringi'.
For example:

x %s/% p

counts how often regular expression specified in character vector p occurs in x, whereas the following,

x %s/% list(fixed=p, case_insensitive=TRUE)

will do the same, except it uses fixed (i.e. literal) expression, and it does not distinguish between upper case and lower case characters.

'tinycodet' adds some convenience functions based on the stri_opts_ - functions in 'stringi':

With the ellipsis (...) being passed to the appropriate 'stringi'-functions when it matches their arguments.

'stringi' infix operators start with "%s", though they all have an alias starting with "%stri". In analogy to that, the above functions start with "s_" rather than "stri_", as they are all meant for infix operators only.

Usage

s_regex(
  p,
  case_insensitive,
  comments,
  dotall,
  multiline,
  time_limit,
  stack_limit,
  ...
)

s_fixed(p, case_insensitive, overlap, ...)

s_coll(
  p,
  locale,
  strength,
  alternate_shifted,
  french,
  uppercase_first,
  case_level,
  numeric,
  normalization,
  ...
)

s_chrcls(p, ...)

Arguments

p

a character vector giving the pattern to search for.
[REGEX]
[FIXED]
[COLL]
[CHARCLASS]

case_insensitive

see stri_opts_regex and stri_opts_fixed.

comments, dotall, multiline

see stri_opts_regex.

time_limit, stack_limit

see stri_opts_regex.

...

additional arguments not part of the stri_opts - functions to be passed here.
For example: max_count

overlap

see stri_opts_fixed.

locale, strength, alternate_shifted

see stri_opts_collator.

french, normalization, numeric

see stri_opts_collator.

uppercase_first, case_level

see stri_opts_collator.

Value

A list with arguments to be passed to the appropriate functions.

See Also

tinycodet_strings()

Examples

x <- c(paste0(letters[1:13], collapse=""), paste0(letters[14:26], collapse=""))
print(x)
p <- rep("a|e|i|o|u", 2) # same as p <- list(regex=rep("a|e|i|o|u", 2))
x %s/% p # count how often vowels appear in each string of vector x.

x <- c(paste0(letters[1:13], collapse=""), paste0(letters[14:26], collapse=""))
print(x)
x %s/% list(regex = rep("A|E|I|O|U", 2), case_insensitive = TRUE)
x %s/% s_regex(rep("A|E|I|O|U", 2), case_insensitive = TRUE)


x <- c(paste0(letters[1:13], collapse=""), paste0(letters[14:26], collapse=""))
print(x)
p <- list(fixed = c("A", "A"), case_insensitive=TRUE)
x %s{}% p
x %s!{}% p
p <- s_fixed(c("A", "A"), case_insensitive=TRUE)
x %s{}% p
x %s!{}% p




[Package tinycodet version 0.3.0 Index]