values: values

Description Usage Arguments Value See Also Examples

Description

Get/set values for a hash object

Usage

1
2
3
4
5
6
7
8
9
values(x, ...)

## S4 method for signature 'hash'
values(x, keys = NULL, ...)

values(x, ...) <- value

## S4 replacement method for signature 'hash'
values(x, ...) <- value

Arguments

x

hash object

...

Unused.

The values method returns a named-list of key value pairs from a hash. If a hash is desired, use the hash slice method, h[x].

List elements are named after the corresponding key. In previous versions, the return was simplified. This is no longer the case. Users should simplify arguments if needed using unlist or similar. See examples.

If argument 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.

keys

character; names of keys to get

value

to be set

Value

A named list. Names are those of the keys, values are the associated hash values.

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
  h <- hash( letters, 1:26 )
  values(h)  # 1:26

  h <- hash( 1:26, letters )
  values(h) 
  values(h, keys=1:5 )
  values(h, keys=c(1,1,1:5) )
  
  values(h, keys=1:5) <- 6:10 
  values(h) <- rev( letters )
      
  # When values are obejcts     
  h <- hash( c('a','b'), Sys.time() )
  class(h$a)             # "POSIXct" "POSIXt"
  vals <- values( h )    
  class( unlist(vals) )            # numeric
  class( Reduce( c, vals ) )       # "POSIXct" "POSIXt" 
  
  vals <- values(h)
  class(vals)            # List
  class( Reduce( c, vals ) ) # "POSIXct" "POSIXt"
  

decisionpatterns/r-hash documentation built on Feb. 6, 2019, 10:27 p.m.