Extract values from a hash object. This is a pseudo- accessor method that returns hash values (without keys) as a vector if possible, a list otherwise.

simplifies them to the lowest order (c.f. simplify). It is very similar to h[[ keys(h) ]] , An optional key. It is identical to h[[ keys(h) ]] .

For details about hash accessors, please see hash-class

# S4 method for class 'hash'
values(x, keys=NULL, ...)
  # S4 method for class 'hash'
values(keys = NULL) <- value

Arguments

x

The hash from where the values retrieved

keys

A vector of keys to be returned.

...

Arguments passed to sapply

value

For the replacement method, the value(s) to be set.

Details

The values method returns the values from a hash. It is similar to h[[ keys(h) ]] except that a named vector or list is returned instead of a hash. : By default, the returned values are simplified by coercing to a vector or matrix if possible; elements are named after the corresponding key. If the values are of different types or of a complex class than a named list is returned. Argument simplify can be used to control this behavior.

If a character vector of keys is provided, only these keys are returned. This also allows for returning values mulitple times as in:

values(h, keys=c('a','a','b' ) )

This is now the preferred method for returning multiple values for the same key.

The replacement method, values<- can replace all the values or simply those associated with the supplied keys. Use of the accessor '[' is almost always preferred.

Value

Please see details for which value will be returned:

vector

Vector with the type as the values of the hash

list

list containing the values of the hash

References

http://blog.opendatagroup.com/2009/10/21/r-accessors-explained/

Author

Christopher Brown

See also

See also hash, sapply.

Examples


  h <- hash( letters, 1:26 )
  values(h)  # 1:26
#>  a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y  z 
#>  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 
  values(h, simplify = FALSE )
#> $a
#> [1] 1
#> 
#> $b
#> [1] 2
#> 
#> $c
#> [1] 3
#> 
#> $d
#> [1] 4
#> 
#> $e
#> [1] 5
#> 
#> $f
#> [1] 6
#> 
#> $g
#> [1] 7
#> 
#> $h
#> [1] 8
#> 
#> $i
#> [1] 9
#> 
#> $j
#> [1] 10
#> 
#> $k
#> [1] 11
#> 
#> $l
#> [1] 12
#> 
#> $m
#> [1] 13
#> 
#> $n
#> [1] 14
#> 
#> $o
#> [1] 15
#> 
#> $p
#> [1] 16
#> 
#> $q
#> [1] 17
#> 
#> $r
#> [1] 18
#> 
#> $s
#> [1] 19
#> 
#> $t
#> [1] 20
#> 
#> $u
#> [1] 21
#> 
#> $v
#> [1] 22
#> 
#> $w
#> [1] 23
#> 
#> $x
#> [1] 24
#> 
#> $y
#> [1] 25
#> 
#> $z
#> [1] 26
#> 
  values(h, USE.NAMES = FALSE )
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#> [26] 26

  h <- hash( 1:26, letters )
  values(h) 
#>   1  10  11  12  13  14  15  16  17  18  19   2  20  21  22  23  24  25  26   3 
#> "a" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "b" "t" "u" "v" "w" "x" "y" "z" "c" 
#>   4   5   6   7   8   9 
#> "d" "e" "f" "g" "h" "i" 
  values(h, keys=1:5 )
#>   1   2   3   4   5 
#> "a" "b" "c" "d" "e" 
  values(h, keys=c(1,1,1:5) )
#>   1   1   1   2   3   4   5 
#> "a" "a" "a" "b" "c" "d" "e" 
  values(h, keys=1:5) <- 6:10 
  values(h) <- rev( letters )