kv: Key value iteration

Description Usage Arguments Details Value References Examples

View source: R/kv.R

Description

Create a list with k and v elements that is useful for explicit iteration

Usage

1
2
3
4
kv(x, ...)

## S3 method for class 'hash'
kv(x, ...)

Arguments

x

object such as vector or list to separate into key value pairs

...

additional arguments

Details

No magic here, just something simple to convert x into a list of lists. Each element of x is broken into a list with elements k (key) and v (value). See examples.

For many cases, key-value iteration can be done with *apply or paste functions. This is made to be explicit and work on a variery of objects.

Value

A named list of list; each element of x becomes a one element list with elements k and v representing the keys and values

References

Examples

1
2
3
4
5
  h <- hash(a=1,b=2,c=3) 
  kv(h)

  for( kv in kv(h) )
    cat( kv$k, ":", kv$v, "\n")

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