% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/klist.r
\name{klist}
\alias{klist}
\alias{is.klist}
\alias{as.klist}
\alias{as.klist.default}
\alias{names<-.klist}
\alias{c.klist}
\title{Create a List With Unique Keys (Named or Unnamed)}
\usage{
klist(...)

is.klist(x)

as.klist(x, ...)

\method{as.klist}{default}(x, ..., .recursive = FALSE)

\method{names}{klist}(x) <- value

\method{c}{klist}(...)
}
\arguments{
\item{...}{for \code{klist}: objects, possibly named, for \code{as.klist}: passed to other
methods.}

\item{x}{object to be coerced or tested.}

\item{.recursive}{boolean indicating whether to recursively validate nested lists.
If \code{TRUE} then all nested lists will be validated and converted to
klists, if \code{FALSE} then only the top level list will be validated
and converted to a klist.}

\item{value}{a character vector of up to the same length as x, or NULL. Resulting names
must be unique.}
}
\value{
A list object of class \code{klist}. For \code{is.klist()} a boolean.
}
\description{
Create a named/unnamed list with unique keys, erroring if any duplicate
keys (names) are found.
}
\details{
\verb{names<-} method for \code{klist} objects will apply the names and then validate
that the resulting names are unique.

\code{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 \link{knlist}.
}
\note{
klists compare names using C's \code{strcmp} function.

\link{as.list} and \link{as.vector} methods for klist objects remove the class
and return a base R list or vector.
}
\examples{
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)))
}
\seealso{
\link{knlist} and \link{keylist}.
}
