[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  list: Lists -- Generic and Dotted Pairs

##  Description

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

##  Usage

    
    
    list(…)
    pairlist(…)
    
    as.list(x, …)
    # S3 method for environment
    as.list(x, all.names = FALSE, sorted = FALSE, …)
    as.pairlist(x)
    
    is.list(x)
    is.pairlist(x)
    
    alist(…)

##  Arguments

…

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
](/link/names?package=base&version=3.6.2) ` 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 ](/link/formals?package=base&version=3.6.2) ` 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 ](/link/formals?package=base&version=3.6.2) ` .

` 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
body. For expressions, the list of constituent elements is returned. ` as.list
` is generic, and as the default method calls ` [ as.vector
](/link/as.vector?package=base&version=3.6.2) (mode = "list") ` for a non-
list, methods for ` as.vector ` may be invoked. ` as.list ` turns a factor
into a list of one-element factors. Attributes may be dropped unless the
argument already is a list or expression. (This is inconsistent with functions
such as ` [ as.character ](/link/as.character?package=base&version=3.6.2) `
which always drop attributes, and is for efficiency since lists can be
expensive to copy.)

` is.list ` returns ` TRUE ` if and only if its argument is a ` list ` _or_ a
` pairlist ` of ` length ` \\(> 0\\). ` is.pairlist ` returns ` TRUE ` if and
only if the argument is a pairlist or ` NULL ` (see below).

The ` " [ environment ](/link/environment?package=base&version=3.6.2) " `
method for ` as.list ` copies the name-value pairs (for names not beginning
with a dot) from an environment to a named list. The user can request that all
named objects are copied. Unless ` sorted = TRUE ` , the list is in no
particular order (the order depends on the order of creation of objects and
whether the environment 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, the ` [ as.environment
](/link/as.environment?package=base&version=3.6.2) () ` method for list
objects.

An empty pairlist, ` pairlist() ` is the same as ` [ NULL
](/link/NULL?package=base&version=3.6.2) ` . This is different from ` list() `
: some but not all operations will promote an empty pairlist to an empty list.

` as.pairlist ` is implemented as ` [ as.vector
](/link/as.vector?package=base&version=3.6.2) (x, "pairlist") ` , and hence
will dispatch methods for the generic function ` as.vector ` . Lists are
copied element-by-element into a pairlist and the names of the list used as
tags for the pairlist: the return