Learn R Programming

hash (version 3.0.1)

hash-class: Class "hash"

Description

Implements a S4 hash class in R similar to hashes / associatesd arrays / dictionaries in other programming languages. Where possible, the hash class uses the standard R accessors: $, [ and [[ as well as other common hash methods. Hash construction is flexible and takes several syntaxes and all hash operations are supported.

Arguments

docType

class

Details

For shorter key-value pairs, lists yield higher performance but hashes outperform list once the have an appreciable length (>100 elements). Hash objects have defined methods that (should) make them flexible, intuitive and easy to use especially from those coming form other languages.

This class provides a hash/dictionary that provides the accessors and other methods common to other programming languages. The haah class inherits from environment and has no defined slots. It is essentially a wrapper arounf environment and is very similar to reference classes in that most of the semantic are pass-by-reference rather than pass-by-value. For this reason, some of the behaviour is not as expected.

See Also

Extract is.hash as.list.hash

Examples

Run this code
h <- new( "hash" )   # new empty hash
  h <- hash()          # same
  class(h)             # "hash"
  is.hash(h)           # TRUE

  h[ letters ] <- 1:26 # populate the hash

  as.list( h )         # convert to a list

  showClass("hash")

Run the code above in your browser using DataLab