| list | R Documentation |
Functions to construct, coerce and check for both kinds ofR lists.
list(...)pairlist(...)as.list(x, ...)## S3 method for class 'environment'as.list(x, all.names = FALSE, sorted = FALSE, ...)as.pairlist(x)is.list(x)is.pairlist(x)alist(...)
... | 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 |
Almost all lists inR internally areGeneric Vectors, whereastraditionaldotted pair lists (as in LISP) remain available butrarely seen by users (except asformals of functions).
The arguments tolist orpairlist are of the formvalue ortag = value. The functions return a list ordotted pair list composed of its arguments with each value eithertagged or untagged, depending on how the argument was specified.
alist handles its arguments as if they described functionarguments. So the values are not evaluated, and tagged arguments withno value are allowed whereaslist simply ignores them.alist is most often used in conjunction withformals.
as.list attempts to coerce its argument to a list. Forfunctions, this returns the concatenation of the list of formalarguments and the function body. For expressions, the list ofconstituent elements is returned.as.list is generic, and asthe default method callsas.vector(mode = "list") for anon-list, methods foras.vector may be invoked.as.listturns a factor into a list of one-element factors. Attributes maybe dropped unless the argument already is a list or expression. (Thisis inconsistent with functions such asas.characterwhich always drop attributes, and is for efficiency since lists can beexpensive to copy.)
is.list returnsTRUE if and only if its argumentis alistor apairlist oflength> 0.is.pairlist returnsTRUE if and only if the argumentis a pairlist orNULL (see below).
The"environment" method foras.list copies thename-value pairs (for names not beginning with a dot) from anenvironment to a named list. The user can request that all namedobjects are copied. Unlesssorted = TRUE, the list is in noparticular order (the orderdepends on the order of creation of objects and whether theenvironment is hashed). No enclosing environments are searched.(Objects copied are duplicated so this can be an expensive operation.)Note that there is an inverse operation, theas.environment() method for list objects.
An empty pairlist,pairlist() is the same asNULL. This is different fromlist(): some butnot all operations will promote an empty pairlist to an empty list.
as.pairlist is implemented asas.vector(x, "pairlist"), and hence will dispatch methods for the generic functionas.vector. Lists are copied element-by-element into a pairlistand the names of the list used as tags for the pairlist: the returnvalue for other types of argument is undocumented.
list,is.list andis.pairlist areprimitive functions.
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)The New S Language.Wadsworth & Brooks/Cole.
vector("list", length) for creation of a list with emptycomponents;c, for concatenation;formals.unlist is an approximate inverse toas.list().
‘plotmath’ for the use oflist in plot annotation.
require(graphics)# create a plotting structurepts <- list(x = cars[,1], y = cars[,2])plot(pts)is.pairlist(.Options) # a user-level pairlist## "pre-allocate" an empty list of length 5vector("list", 5)# Argument listsf <- function() x# Note the specification of a "..." argument:formals(f) <- al <- alist(x = , y = 2+3, ... = )fal## environment->list coercione1 <- new.env()e1$a <- 10e1$b <- 20as.list(e1)Add the following code to your website.
For more information on customizing the embed code, readEmbedding Snippets.