The searchable package provides flexibile methods for searching and subsetting list, vectors and other objects by matching names using case (in)sensitivity, regular expressions, fixed expressions or other user defined patterns. This is accomplished by overloading the standard [
operator to allow string[r|i]
style match modifiers. These can used to change the default search semantics on an object or change search behavior on the fly. When no match modifiers are used, the default is standard R behavior, so this functions as a drop-in replacement.
searchable
was designed to be extensible. Developers can use searchable
to build thier own flexible, high performance dictionary and thesaurus data structures or their own match modifiers
Features of this package are:
[
operator is overload but defaults to base-R functionality. Stable Version:
install.packages('searchable')
library(devtools)
Development Version:
library(devtools)
install_github( "decisionpatterns/searchable" )
library(searchable)
library(magrittr)
# ATOMIC VECTORS:
v <- c( a=1, b=2, B=3, c=4, c2=5 )
sv <- searchable(v)
# EXTRACT:
sv$a
sv[['a']]
sv[[ ignore.case('A') ]] # Ad-hoc case-insensitive matching
sv[ ignore.case('b') ]
sv[ perl('c') ]
sv[ fixed('c') ]
# REPLACEMENT:
sv$a <- "first"
sv[['a']] <- "1st"
sv[[ perl('c.') ]] <- "third"
sv[ perl('c.?') ] <- "3rd"
# MODIFIERS TO SEARCH TARGET/OBJECT
sv <- searchable(v, ignore.case ) # Defines default case-insensitive matching
sv$A
sv['b']
sv['B']
# 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[[ . ]]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.