pattern: Pattern matching operators

Description Usage Arguments Value Note Author(s) See Also Examples

Description

Set of convenience functions to handle strings and pattern matching. These are basically companion binary operators for the classic R function grep and regexpr.

Usage

1
2
3
4
5
6
7
8
9
  x %~% rx
  x %!~% rx
  
  x %~*% rx
  x %!~*% rx

  x %~+% rx
  x %!~+% rx
  

Arguments

x

text to manipulate

rx

regular expression

Value

%~% : gives a logical vector indicating which elements of x match the regular expression rx. %!~% is the negation of %~%

%~*% : gives a single logical indicating if all the elements of x are matching the regular expression rx. %!~*% is the negation of %~*%.

%~+% : gives a single logical indicating if any element of x matches the regular expression rx. %!~+% is the negation of %~+%.

Note

The matching is done using a modified version of the regexpr function. The modification is performed by applying the operators.regexpr option to the regexpr function via the %but% operator.

The default version of regexpr enables the perl and extended options. See %but% for details.

Author(s)

Romain Francois <francoisromain@free.fr>

See Also

grep, gsub, %~|% for regular expression filters

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
                        
  txt <- c("arm","foot","lefroo", "bafoobar")
  txt %~% "foo"
  txt %!~% "foo"
  txt %~*% "foo"
  txt %~+% "foo"
  txt %!~*% "foo"
  txt %!~+% "foo"
  
  txt %~%   "[a-z]"
  txt %!~%  "[a-z]"
  txt %~*%  "[a-z]"
  txt %~+%  "[a-z]"
  txt %!~*% "[a-z]"
  txt %!~+% "[a-z]"
  
  
  cols <- colors()
  cols[ cols %~% "^blue" ]
  # see also %~|%
  
  
  ## needs perl regular expression for the \\d, see %but%
  with( options( operators.regexpr = "p" ), {
  	cols[ cols %!~% "\\d$" ]
  } )
  

operators documentation built on May 2, 2019, 6:48 p.m.