set: assign key-value pair(s) to a hash

Description Usage Arguments Details Value Author(s) See Also Examples

Description

.set is an internal method for assigning key-value pairs to a hash. Normally, there is no need to use this function. Convenient access is provided by: hash, \$, [ and [[ and their corresponding replacement methods.

.set takes 4 types of arguments: explicitly named key and value vectors named key-value pairs named vectors implicit key-value pairs

The keys are automatically coerced to valid keys and are restricted to character classes. Values are free to be any valid R object.

Usage

1
  .set( hash, ... )

Arguments

hash

An hash object on which to set the key-value pair(s)

...

Any of several ways to specify keys and values. See Details.

Details

.set sets zero or more key-value pairs. If the key(s) already exist, existing values are silently clobbered. Otherwise, a new value is saved for each key. Keys and values are by the ... argument. If ... is:

made only of explicitly named keys and values arguments then these are taken as the keys and values respectively.

a named list, then the names are taken as keys and list elements are taken as values.

a named vector, then the names are taken as keys. Vector elements are taken as values.

of length two, keys are taken from the first element, values from the second.

Keys are coerced to type character.

Keys and values are assigned to the hash as follows:

IF keys and values are the same length, key-value pairs are added to the hash pairwise.

IF keys is a vector of length 1, then this key is assigned the entire values vector.

IF values is a vector of length 1, each key of keys is assigned the value given by values

IF keys and values are of different lengths, both greater than one, then the assignment is considered ambiguous and an error is thrown.

Value

.set exists solely for its side-effects. An invisible NULL is returned.

Author(s)

Christopher Brown

See Also

See also hash, environment

Examples

1
2
3
4
5
6
7
  h <- hash()

  .set( h, keys=letters, values=1:26 )
  .set( h, a="foo", b="bar", c="baz" )
  .set( h, c( aa="foo", ab="bar", ac="baz" ) )
  clear(h)
  .set( h, letters, values )

hash documentation built on May 1, 2019, 7:28 p.m.