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

Provides functionality for searching / subsetting and slicing named objects using 'stringr/i'-style modifiers by case (in)sensitivity, regular expressions 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.


The 'searchable' package provides flexibile methods for subseting
object by matching objects 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.

Features of this package are:

  • 'stringr/i'-style match modifiers for matching names by case (in)sensitivity, regular expressions or fixed expression.

  • Match modification applied to either/both the pattern and target.

  • The [ operatore overloaded to provide R-like functionality.

  • Search behavior defaults to base R behaviors.

Installation

library(devtools)
install_github( "decisionpatterns/searchable" )

# OR 
install.packages('searchable')

Examples

  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') ]]
    
    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 )         
    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[[ . ]]
 
     

News

Version 0.3.3 "Billie Holiday"

  • Fixes to DESCRIPTION and docs to get by CRAN censors

Version 0.3 "Drowsey Driver"

  • Move dependency from stringr to stringi

  • Remove methods for $, $<-, [[, [[<-: These are indeterminant and lead to ambiguous results

  • Class names are now CapWords

  • Code better factored into files

Version 0.2 "happy birthday"

  • Adds support for multiple patterns with [. Multiple pattern searches return elements of the search target that match ANY of the patterns.

  • Clarifies the documentation

  • Fixes problems with tests

  • Adds this NEWS file

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("searchable")

0.3.3.1 by Christopher Brown, 4 years ago


https://github.com/decisionpatterns/searchable


Report a bug at https://github.com/decisionpatterns/searchable/issues


Browse source code at https://github.com/cran/searchable


Authors: "DecisionPatterns [aut, cre]"


Documentation:   PDF Manual  


GPL-2 license


Imports methods, magrittr, stringi

Suggests testthat


See at CRAN