searchable makes a named object a
Searchable target, optionally
specifying the default search options.
1 2 3 4
searchable object or object to be made searchable
character; the type of search to perform
additional arguments defining the search pattern. See
The searchable class allows 'stringr/i'-like searches using
\[<- operators. The following search types are supported:
std standard R matching, the default
regex for regular expression matching,
fixed for fixed string matching,
coll for collation matching,
Searchable objects allow customizations of how R's
\[ operator match objects' names.
By default, extraction from a searchable objects does not produce a subset that is also searchable. It is assumed that in most cases, the developer will not want another searchable object and only wish to have the subclass.
stringi are general purpose string manipulations
library allowing flexible search and pattern matching against character
searchable package applies this type of matching
to objects' names using the standard
\[ accessor. Thus,
searchable(sv)[ regex('b') ]
returns objects the subset of whose names contain 'b'.
searchable allows search specification
to applied to either the search pattern or search target.
When applied to the target, a default search method is configured. All
subsequent searches of the searchable target will use this default pattern.
The search method can be specified with the
type argument of the
searchable function or any of match-modifying functions,
When modifiers are applied to both target and pattern, modifers applied to the pattern take precedence and the target's modifiers are disabled.
searchable is designed to be minimally invase. When no search types
or options are specified, mathcing defaults to R's normal behavior.
Here are the other differnece from standard R operations:
\[\[ are unaltered by the package. It is unclear, how these operators might accommodate the indeterminate number of matches.
Searches using multiple patterns recylce the patterns, but rather return elements that match any of the patterns.
In base R, there is output value every element of input argument,
i. Input elements that do not match a named element of
NA. Because of the indeterminant number of
matches given a pattern search against a
there is no guarantee that a search pattern have a match. If no
matches are found, a zero-length object is returned. (This may change
NA to be more consisitent.)
Results do not yield a Searchable object, but the superclass that the searchable class wraps. See Value below.
searchable can be used to replace objects as well. See
for additional exemples.
Multiple dimension ojects such as data.frames, data.tables, matrices and arrays are not supported at this time.
- Environments cannot be (easily) be made "searchable" due to the way the they are implemented.
- The extraction methods for searchable objects are (at present) limited to only one pattern. This may change in the future.
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.