strict_list: Strict lists

Description Usage Arguments Details Value Examples

View source: R/data-structure.R

Description

A strict list is essentially a normal list() but it does not allow partial matching with $.

Usage

1
2
3
4
5
6
7
strict_list(...)

## S3 method for class 'xfun_strict_list'
x$name

## S3 method for class 'xfun_strict_list'
print(x, ...)

Arguments

...

Objects (list elements), possibly named. Ignored in the print() method.

x

A strict list.

name

The name (a character string) of the list element.

Details

To me, partial matching is often more annoying and surprising than convenient. It can lead to bugs that are very hard to discover, and I have been bitten for many times. When I write x$name, I always mean precisely name. You should use a modern code editor to autocomplate the name if it is too long to type, instead of using a partial name.

Value

strict_list() returns a list with the class xfun_strict_list.

Examples

1
2
3
4
5
6
7
8
9
library(xfun)
(z = strict_list(aaa = "I am aaa", b = 1:5))
z$a  # NULL!
z$aaa  # I am aaa
z$b
z$c = "create a new element"

z2 = unclass(z)  # a normal list
z2$a  # partial matching

yihui/xfun documentation built on Oct. 25, 2018, 11:44 p.m.