hash-package | R Documentation |
This S4 class is designed to provide a hash-like data structure in a native R style and provides the necessary methods for all general methods for hash operations.
R is slowly moving toward a native implementation of hashes
using environments, (cf. Extract
. Access to
environments using $ and [[ has been available for some time and
recently objects can inherit from environments, etc. But many features
that make hashes/dictionaries great are still lacking, such
as the slice operation, [.
The hash package is the only full featured hash implementation for the R language. It provides more features and finer control of the hash behavior than the native feature set and has similar and sometimes better performance.
HASH KEYS must be a valid character value and may not be the empty
string ""
.
HASH VALUES can be any R value, vector or object.
PASS-BY REFERENCE. Environments and hashes are special objects in R because only one copy exists globally. When provide as an argument to a function, no local copy is made and any changes to the hash in the functions are reflected globally.
PERFORMANCE. Hashes are based on R's native environments and are designed to be exceedingly fast using the environments internal hash table. For small data structures, a list will out-perform a hash in nearly every case. For larger data structure, i.e. > 500 key value pair the performance of the hash becomes faster. Much beyond that the performance of the hash far outperforms native lists.
MEMORY. Objects of class hash
do not release memory with a call to
rm
. clear
must be called before rm
to properly
release the memory.
Christopher Brown
Maintainer: Christopher Brown <chris.brown -at- decisionpatterns -dot- com>
http://www.mail-archive.com/r-help@r-project.org/msg37637.html
http://www.mail-archive.com/r-help@r-project.org/msg37650.html
See also hash
, hash-accessors
and
environment
h <- hash( keys=letters, values=1:26 )
h <- hash( letters, 1:26 )
h$a # 1
h$foo <- "bar"
h[ "foo" ]
h[[ "foo" ]]
clear(h)
rm(h)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.