Learn R Programming

searchable (version 0.3.3.1)

searchable-package: searchable

Description

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

Arguments

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

Run this code
# 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
   sl[ "B"  %>% ignore.case ]
    "b" %>% sl[.]
    "B" %>% ignore.case %>% sl[.]

Run the code above in your browser using DataLab