Description Usage Arguments Value [, [<- See Also Examples
Defines [
, [[
, and $
for Searchable objects
1 2 3 4 5 |
x |
Searchable object |
i |
character; pattern with potential match modifiers applied, |
j |
missing; never specified |
... |
additional arguments. See |
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 |
value |
replacement value for replacement functions The methods for searching respect the modifiers applied to both |
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:
The search returns elements of the target that matches ANY of the search patterns.
Unlike the
its normal behavior, \[
does not guarantee the output to have as many
elements as elements to pattern
.
[
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 using searchable
however.
Unlike for environments and hashes, no constraints exist for ensuring
uniqueness for names in vectors and lists. These structures may contain
multiple elements with the same name. Normal attempts to extract by name
yield only the first element that matches the name. Using a
Searchable
patterns match yields all matching elements.
Searchable
Extract
Match mofiers: fixed
, regex
,
coll
and ignore.case
reverse.lookup
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.