extract: Extract

Description Usage Arguments Author(s) See Also Examples

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## S4 method for signature 'hash,ANY,missing,missing'
x[i, j, ..., drop = TRUE]

## S4 method for signature 'hash,missing,missing,missing'
x[i, j, ..., drop = TRUE]

## S4 replacement method for signature 'hash,ANY,missing,ANY'
x[i, j, ...] <- value

## S4 replacement method for signature 'hash,ANY,missing,'NULL''
x[i, j, ...] <- value

## S4 replacement method for signature 'hash,'NULL''
x$name <- value

## S4 replacement method for signature 'hash,ANY,missing,ANY'
x[[i]] <- value

## S4 replacement method for signature 'hash,ANY,missing,'NULL''
x[[i]] <- value

Arguments

x

hash() object

i

keys to get or set

j

unused; retained to be compatoble with base package

...

Arguments passed to additional methods sapply()

drop

unused; retained to be compatible with base package

value

the value to set for the key-value pair

name

the key name

$ is a look-up operator for a single key. The base $ method are used directly on the inherited environment. The supplied key is taken as a string literal and is not interpreted. The replaement form, $<- mutates the hash in place.

[[ is the look-up, extraction operator. It returns the value of a single key and will interpret its argument. The replacement method, [[<- mutates the hash in place.

[ is a slice operator. It returns a hash with the subset of key-value pairs. Unlike the other accessor methods, [ returns a copy.

All hash key misses return NULL. All hash key replacements with NULL delete the key-value pair from the hash.

$ and [[ return the value for the supplied argument. If i is not a key of x, NULL is returned with a warning.

[ returns a hash slice, a subhash copy x with only the keys i defined.

See details above for the complete explanation.

Author(s)

Christopher Brown

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
23
24
25
26
27
28
29
30
31
32
33
  h <- hash( c('a','b','c'), 1:3 )

  # NAMED ACCESS
  
  h$a  # 1
  h$c  # 3
  
  # class of values change automatically
  class(h$a)  # integer
  h$a <- 1.1 
  class(h$a)  # numeric
  
  # values can contain more complex objects
  h$a <- 1:6
  h

  h$a <- NULL  # DELETE key 'a', will return null
  
  
  # INTERPRETED ACCESS
  
  h[[ "a" ]] <-"foo"    # Assigns letters, a vector to "foo"
  nm = "a"
  
  # SLICE ACCESS
  h[ nm ] <- "bar"   # h$a == bar
  h[ nm ] <- NULL
  
  
  # Slice 
  h[ keys(h) ]
  h[ keys(h) ] <- list( 1:2, 1:3 )
  h

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