Learn R Programming

hash (version 1.10.0)

hash-accessors: Accessor methods for the hash class.

Description

R style accesors for the hash-class.

Arguments

Value

$ and [[ return the value for the supplied argument. If a key does not match an existing key, then NULL is returned with a warning.

[ returns a hash slice, a sub hash with only the defined keys.

Details

These are the hash accessor methods. They closely follow an R style.

$ is a look-up operator for a single key. The key is coerced to valid hash key via make.keys returns the corresponding value. The key name must be literal it is not interpreted.

[[ is the look-up, extraction operator. It returns the values of a single key. The key names will be interpreted and coerced to a valid hash key via make.keys. [ is a subseting operator. It returns a (sub) hash with the specified keys. All other keys are removed. Key names are coerced via make.keys

See Also

hash, .set, as.list.hash

Examples

Run this code
h <- hash()
  h <- hash( letters, 1:26 )

  h$a 			
  h$a <- "2"   

  h[[ "a" ]] # c("a","b","c","d") 

  h[ letters[1:4] ]    # hash with a,b,c,d
  h[ letters[1:4] ] <- 4:1

Run the code above in your browser using DataLab