[
, [[
, and $
for Searchable objects## S3 method for class 'Searchable,PatternOrCharacter,missing':
[(x, i, j, ..., drop = TRUE)## S3 method for class 'Searchable,character,missing':
[(x, i) <- value
Extract
drop
for further details.The methods for searching respect the modifiers applied to both x
and
i
.
[
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:[
does not guarantee the output to have as many
elements as elements topattern
.[
does not return a Searchable object. It is thought that
the return valuable will not be subsequently searched. It is easy to turn
the results into a Searchable object usingsearchable
however.Searchable
patterns match yields all matching elements.Searchable
Extract
Match mofiers: fixed
, regex
,
coll
and ignore.case
reverse.lookup
# 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 sl[ "B" %>% ignore.case ] "b" %>% sl[.] "B" %>% ignore.case %>% sl[.]