Description Usage Arguments Details Value Author(s) See Also Examples
Functions for creating and working with hash objects:
Returns the number of items in a hash
1 2 3 4 5 6 7 8 9 |
... |
Additional arguments passed to the function
#' HASH KEYS must be a valid character value and may not be the empty string
|
x |
a hash object. |
all.names |
a logical indicating whether to copy all values or (default) only those whose names do not begin with a dot |
hash
Class constructor
is.hash
test if object is of class "hash"
as.list
as.list.hash
convert a hash object to a list
KEYS must be a valid R name, must be a character vector and must not
be the empty string, ""
. When supplied by the used methods will try to
coerce the keys to valid names using make_keys()
VALUES are restricted to any valid R objects. HASH VALUES can be any R value, vector or object.
codehash returns a hash object. Key-value pairs may be specified
as:
explicitly named arguments keys
and values
two unnamed objects of equal length as a set of key-value pairs
key=value pairs
a single naned vector
as a list
ACCESSORS. Hashes may be accessed via the standard R accessors [
, [[
and
\$
. See hash::extract()
for details.
PASS-BY REFERENCE. Environments and hashes are special objects in R because only one copy exists globally. When provided as an argument to a function, no local copy is made. When passes to functions, those functions can change the value of the hash. This is not typical of R.
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.
Return the number of items in the hash by calling length()
on
the internal environment.
hash
hash object
is.hash
logical value indicating if the argument is a hash.
as.list
list conversion from hash
length
integer; number of key-value pairs in the hash
integer Number of items in the hash.
Christopher Brown
Christpher Brown
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | hash() # empty
h <- hash() # associate a name to the hash
hash( new.env() ) # from environment
hash( a=1, b=2, c=3 ) # key-value pairs using named arguments
hash( letters[1:3], 1:3 ) # unamed args: two equal length vectors
hash( letters[1:3], 1 ) # unamed args: all keys with same value
hash( 1:3, lapply(1:3, seq, 1 )) # same, arbitrary values
hash( c(a=1, b=2, c=3) ) # named vector of key-value pairs
hash( list(a=1,b=2,c=3) ) # named list of key-value pairs
is.hash( hash() )
as.list(h) # CONVERT TO LIST
h <- hash( letters, 1:26 )
length(h) # 26
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.