list_named: Automatically Named list()

list_namedR Documentation

Automatically Named list()

Description

A version of list(...), but with “automatically” named list components.

Usage

list_(...)

Arguments

...

components to make up the resulting list. Their variable names (or unevaluated expressions in the call) will become the names(.) of the result.

Details

The names are extracted from sys.call(), and the function is written to be fast (rather than easy to ready for the uninitiated ;-)

Value

a list with the components in the arguments with names taken from their call to list_(..).

Author(s)

Martin Maechler

See Also

list, names

Examples

a <- 1:4; lett <- letters[1:9]; CH <- "Suisse"
all.equal(list (a, lett),
          list_(a, lett)) # "names for current but not for target"
str(list(a, lett, CH)) # [[1]], [[2]], .. (no names)
str(list_(a, lett, CH))#   $a   $lett  ..

stopifnot(identical(            list (a, lett, CH),
                    unname(L <- list_(a, lett, CH))),
          is.list(L), names(L) == c("a", "lett", "CH"),
          identical(lett, L$lett) ## etc
          )

## The function is currently defined as
function (...) `names<-`(list(...), vapply(sys.call()[-1L], as.character, ""))

mmaechler/sfsmisc documentation built on Feb. 28, 2024, 4:18 a.m.