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

is.knlist(x)

as.knlist(x, ...)

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

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

\method{c}{knlist}(...)
}
\arguments{
\item{...}{for \code{knlist}: named objects, for \code{as.knlist}: 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
knlists, if \code{FALSE} then only the top level list will be validated
and converted to a knlist.}

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

\code{c.knlist} method will combine the objects and then validate that the
resulting knlist's names are unique.

For a list with unique keys of names and indexes, see \link{klist}.
}
\note{
knlists 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{
x <- knlist(a = 1, b = 2, c = 3)
try(knlist(b = 1, a = 2, a = 1)) # duplicate keys not allowed
try(x[[1]] <- 1) # knlist only accepts character indexing for assignment

# objects within a knlist are not subject to validation
knlist(x = 1, y = list(a = 1, a = 2))
try(knlist(x = 1, y = knlist(a = 1, a = 2))) # but nested knlists are

# recursively validate and convert to knlist
x <- list(a = 1, b = list(x = 1, y = 2))
x <- as.knlist(x, .recursive = TRUE)
class(x[[2]]) # nested list is now a knlist

is.knlist(knlist(a = 1)) # TRUE

try(names(x) <- c("a", "a")) # names are validated when changed

# c() method for knlist objects also validates
try(c(knlist(a = 1), list(a = 3)))
}
\seealso{
\link{klist} and \link{keylist}.
}
