| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/data-structure.R |
| 3 |
\name{strict_list} |
| 4 |
\alias{strict_list} |
| 5 |
\alias{as_strict_list} |
| 6 |
\alias{$.xfun_strict_list} |
| 7 |
\alias{print.xfun_strict_list} |
| 8 |
\title{Strict lists} |
| 9 |
\usage{ |
| 10 |
strict_list(...) |
| 11 |
|
| 12 |
as_strict_list(x) |
| 13 |
|
| 14 |
\method{$}{xfun_strict_list}(x, name) |
| 15 |
|
| 16 |
\method{print}{xfun_strict_list}(x, ...) |
| 17 |
} |
| 18 |
\arguments{ |
| 19 |
\item{...}{Objects (list elements), possibly named. Ignored in the |
| 20 |
\code{print()} method.} |
| 21 |
|
| 22 |
\item{x}{For \code{as_strict_list()}, the object to be coerced to a strict |
| 23 |
list. |
| 24 |
|
| 25 |
For \code{print()}, a strict list.} |
| 26 |
|
| 27 |
\item{name}{The name (a character string) of the list element.} |
| 28 |
} |
| 29 |
\value{ |
| 30 |
Both \code{strict_list()} and \code{as_strict_list()} return a list |
| 31 |
with the class \code{xfun_strict_list}. Whereas \code{as_strict_list()} |
| 32 |
attempts to coerce its argument \code{x} to a list if necessary, |
| 33 |
\code{strict_list()} just wraps its argument \code{...} in a list, i.e., it |
| 34 |
will add another list level regardless if \code{...} already is of type |
| 35 |
list. |
| 36 |
} |
| 37 |
\description{ |
| 38 |
A strict list is essentially a normal \code{\link[=list]{list()}} but it does not |
| 39 |
allow partial matching with \code{$}. |
| 40 |
} |
| 41 |
\details{ |
| 42 |
To me, partial matching is often more annoying and surprising than |
| 43 |
convenient. It can lead to bugs that are very hard to discover, and I have |
| 44 |
been bitten by it many times. When I write \code{x$name}, I always mean |
| 45 |
precisely \code{name}. You should use a modern code editor to autocomplete |
| 46 |
the \code{name} if it is too long to type, instead of using partial names. |
| 47 |
} |
| 48 |
\examples{ |
| 49 |
library(xfun) |
| 50 |
(z = strict_list(aaa = "I am aaa", b = 1:5)) |
| 51 |
z$a # NULL! |
| 52 |
z$aaa # I am aaa |
| 53 |
z$b |
| 54 |
z$c = "create a new element" |
| 55 |
|
| 56 |
z2 = unclass(z) # a normal list |
| 57 |
z2$a # partial matching |
| 58 |
|
| 59 |
z3 = as_strict_list(z2) # a strict list again |
| 60 |
z3$a # NULL again! |
| 61 |
} |