as.keyvalue.list.Rd
x
should be a list with properties described in section "Details".
# S3 method for list as.keyvalue(x, ...)
x | a |
---|---|
... | further arguments passed to |
The function returns an object of class keyvalue
(and list
.
All names of the list elements should be unique.
All elements of the list should be named.
All keys should be unique (a key should only be mappad to one value).
All elements of the list should be atomic vectors.
ex <- list( fruit = c("banana", "orange", "kiwi"), car = c("SAAB", "Volvo", "taxi", "truck"), animal = c("elephant") ) as.keyvalue(ex)#> key value #> 1 banana fruit #> 8 elephant animal #> 3 kiwi fruit #> 2 orange fruit #> 4 SAAB car #> 6 taxi car #> 7 truck car #> 5 Volvo caris.keyvalue(ex)#> [1] FALSE# \donttest{ # An invalid list (non unique names; not because of silly classification) ex2 <- list( fruit = c("banana", "orange", "kiwi"), car = c("SAAB", "Volvo", "taxi", "truck"), animal = c("elephant"), fruit = c("President_Obama") ) as.keyvalue(ex2)#> Error in as.keyvalue.list(ex2): All list element names must be unique!# An invalid list (non unique keys; kiwi appear twice) ex3 <- list( fruit = c("banana", "orange", "kiwi"), car = c("SAAB", "Volvo", "taxi", "truck"), animal = c("elephant", "kiwi") ) as.keyvalue(ex3)#> Error in as.keyvalue.list(ex3): Some key(s) have duplicates! A key should only be mapped to one value (be found in one element of the list)# }