searchable-package: searchable

Description Details References See Also Examples

Description

Tools For Custom Searches / Subsets / Slices of Named R Objects

Details

The 'searchable' package provides flexibile methods for subseting named object by matching the names using case (in)sensitivity, regular or fixed expressions. searches uses the standard '[' operator and allows specification of default search behavior to either the search target (named object) and/or the search pattern.

It was designed to make flexible, high performance dictionary and thesaurus structures.

References

http://stackoverflow.com/questions/5671719/case-insensitive-search-of-a-list-in-r
http://stackoverflow.com/questions/27085620/which-command-in-r-with-case-insensitive
http://stackoverflow.com/questions/21450925/r-grep-usage-finding-the-averages

See Also

searchable
http://cran.r-project.org/web/packages/qdap

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
44
# 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"
    sv


  # 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)

searchable documentation built on May 29, 2017, 12:30 p.m.