https://github.com/decisionpatterns/r-hash
  
  
    Full feature implementation of hash/associated arrays/dictionaries in R 
    https://github.com/decisionpatterns/r-hash
  
        Last synced: 3 months ago 
        JSON representation
    
Full feature implementation of hash/associated arrays/dictionaries in R
- Host: GitHub
- URL: https://github.com/decisionpatterns/r-hash
- Owner: decisionpatterns
- License: other
- Created: 2013-12-01T19:43:54.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2019-02-05T16:10:00.000Z (over 6 years ago)
- Last Synced: 2024-08-13T07:15:26.704Z (about 1 year ago)
- Language: R
- Size: 148 KB
- Stars: 29
- Watchers: 4
- Forks: 3
- Open Issues: 6
- 
            Metadata Files:
            - Readme: README.md
- License: LICENSE
 
Awesome Lists containing this project
- jimsghstars - decisionpatterns/r-hash - Full feature implementation of hash/associated arrays/dictionaries in R (R)
README
          # hash 
## hash/dictionary/maps in R
  
  
[](https://www.tidyverse.org/lifecycle/#stable)
[](https://www.r-pkg.org/pkg/hash)
[](https://cran.r-project.org/package=hash)
The *hash* package provides a fully-functional hash/dictionaryfor the R language. It provides richer features and finer control of hash behavior than using native R structures like list or environments and has as a user-friendly interface. Performance-wise it has similar and sometimes better performance than these structures especially for larger objects.
## Installation
Latest Release:
    install.packages('hash')
Development Version:
    install.packages('devtools')
    devtools::install_github('decisionpatterns/r-hash')
## Examples 
    # Create a hash 
    h <- hash(a=1, b=2, c=3)
    h <- hash( letters[1:3], 1:3 )
    h <- hash( list(a=1,b=2,c=3) )  
     
    # Keys 
    keys(h)
     
    # Values (named list)
    values(h)
     
    # Assign to single key hash
    h$a <- "foo"
    h[['a']] <- "bar"
     
    # Slice
    h[ c('a','c') ]
    
## Allowable Values  
**KEYS** must be a valid character value and may not be the empty string (""). Keys must be unique.
**VALUES** can be any R value, vector, object, etc. 
## Usage Notes
Hashes probably work about how you would expect, but since there are built from R's native environments. There are three things to Remember:
**PASS-BY REFERENCE**. hashes are environments, special objects in R where only one copy exists globally. When passed as an argument to a function, no local copy is made and any changes to the hash in the functions are reflected globally, i.e. in the caller's namespace.
**PERFORMANCE**.  Hashes are designed to be exceedingly fast using R environment's internal hash table.  The hash function is not without its cost. For small data structures, a named lists and vectors will out-perform a hash in nearly every case. After approximately 500+ elements, the performance of the hash becomes faster than native lists and vectors.