| klist | R Documentation |
Create a named/unnamed list with unique keys, erroring if any duplicate keys (names) are found.
klist(...)
is.klist(x)
as.klist(x, ...)
## Default S3 method:
as.klist(x, ..., .recursive = FALSE)
## S3 replacement method for class 'klist'
names(x) <- value
## S3 method for class 'klist'
c(...)
... |
for |
x |
object to be coerced or tested. |
.recursive |
boolean indicating whether to recursively validate nested lists.
If |
value |
a character vector of up to the same length as x, or NULL. Resulting names must be unique. |
names<- method for klist objects will apply the names and then validate
that the resulting names are unique.
c.klist method will combine the objects and then validate that the
resulting klist's names are unique.
For a list with unique keys of all names, see knlist.
A list object of class klist. For is.klist() a boolean.
klists compare names using C's strcmp function.
as.list and as.vector methods for klist objects remove the class and return a base R list or vector.
knlist and keylist.
klist(a = 1, 2, b = 3)
try(klist(1, a = 2, a = 1)) # duplicate keys not allowed
# objects within a klist are not subject to validation
klist(1, list(a = 1, a = 2))
try(klist(1, klist(a = 1, a = 2))) # but nested klists are
# recursively validate and convert to klist
x <- list(1, list(1, 2))
x <- as.klist(x, .recursive = TRUE)
class(x[[2]]) # nested list is now a klist
is.klist(klist(1)) # TRUE
try(names(x) <- c("a", "a")) # names are validated when changed
# c() method for klist objects also validates
try(c(klist(a = 1), list(a = 3)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.