extract: Extraction operators for Searchable object

Description Usage Arguments Value [, [<- See Also Examples

Description

Defines [, [[, and $ for Searchable objects

Usage

1
2
3
4
5
## S4 method for signature 'Searchable,PatternOrCharacter,missing'
x[i, j, ..., drop = TRUE]

## S4 replacement method for signature 'Searchable,character,missing'
x[i] <- value

Arguments

x

Searchable object

i

character; pattern with potential match modifiers applied,

j

missing; never specified

...

additional arguments. See Extract

drop

For matrices and arrays. If TRUE the result is coerced to the lowest possible dimension (see the examples). This only works for extracting elements, not for the replacement. See drop for further details.

value

replacement value for replacement functions

The methods for searching respect the modifiers applied to both x and i.

Value

The values after the extracting methods have been applied:
\[ returns a subset of x, but which is not Searchable.
\[\[ and \$ return a sinlge element of x

[, [<-

[ and [<- are used for subsetting and replacing zero or more elemenxts of x. Used with searchable objects, these operators differ from normal R operations in the following respects:

See Also

Searchable
Extract
Match mofiers: fixed, regex, coll and ignore.case reverse.lookup

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
# ATOMIC VECTORS:
    v <- c( a=1, b=2, B=3, c=4, c2=5 )
    sv <- searchable(v)


  # FLEXIBLY FIND ELEMENTS BY NAME
    sv[ regex('c') ]
    sv[ fixed('c') ]

    sv[ ignore.case('b') ]


  # FLEXIBLY REPLACEMENT ELEMENTS BY NAME
    sv[ regex('c.?') ]   <- "3rd"


  # SET DEFAULT SEARCH FOR TARGET/OBJECT
    sv <- searchable(v, case_insensitive = TRUE )
    sv['b']
    sv['B']

    sv <- regex(sv)
    sv['c']

    sv <- ignore.case(sv)
    sv['b']
    sv['c']                  # st


  # USE ON (RECURSIVE) LISTS:
    l <- list( a=1, b=2, c=3 )
    sl <- searchable(l)
    sl["b"]
    sl[ ignore.case("B") ]


  # USE WITH MAGRITTR
   ## Not run: 
    sl[ "B"  %>% ignore.case ]
    "b" %>% sl[.]
    "B" %>% ignore.case %>% sl[.]
   
## End(Not run)

decisionpatterns/searchable documentation built on Jan. 8, 2019, 3:28 a.m.