ID EN
Vector & List

list

R Base 3.6.2

Functions to construct, coerce and check for both kinds of R lists.

Syntax

R
list(…)
pairlist(&#8230;)<p></p><p>as.list(x, &#8230;)
# S3 method for environment
as.list(x, all.names = FALSE, sorted = FALSE, &#8230;)
as.pairlist(x)</p><p>is.list(x)
is.pairlist(x)</p><p>alist(&#8230;)</p>

Arguments

Parameter Description
&#8230; objects, possibly named.
x object to be coerced or tested.
all.names a logical indicating whether to copy all values or (default) only those whose names do not begin with a dot.
sorted a logical indicating whether the names of the resulting list should be sorted (increasingly). Note that this is somewhat costly, but may be useful for comparison of environments.

Details

Almost all lists in R internally are Generic Vectors, whereas traditional dotted pair lists (as in LISP) remain available but rarely seen by users (except as formals of functions). The arguments to list or pairlist are of the form value or tag = value. The functions return a list or dotted pair list composed of its arguments with each value either tagged or untagged, depending on how the argument was specified. alist handles its arguments as if they described function arguments. So the values are not evaluated, and tagged arguments with no value are allowed whereas list simply ignores them. alist is most often used in conjunction with formals. as.list attempts to coerce its argument to a list. For functions, this returns the concatenation of the list of formal arguments and the function bo

Examples

Example
R
# NOT RUN {
require(graphics)

# create a plotting structure
pts <- list(x = cars[,1], y = cars[,2])
plot(pts)

is.pairlist(.Options)  # a user-level pairlist

## "pre-allocate" an empty list of length 5
vector("list", 5)

# Argument lists
f <- function() x
# Note the specification of a "..." argument:
formals(f) <- al <- alist(x = , y = 2+3,
# }
# NOT RUN {
…
# }
# NOT RUN {
 = )
f
al

## environment->list coercion

e1 <- new.env()
e1$a <- 10
e1$b <- 20
as.list(e1)
# }

See Also

vector("list" length) for creation of a list with empty components; c for concatenation; formals. unlist is an approximate inverse to as.list(). ‘plotmath’ for the use of list in plot annotation.