list                  package:base                  R Documentation

_L_i_s_t_s - _G_e_n_e_r_i_c _a_n_d _D_o_t_t_e_d _P_a_i_r_s

_D_e_s_c_r_i_p_t_i_o_n:

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

_U_s_a_g_e:

     list(...)
     pairlist(...)

     as.list(x, ...)
     ## S3 method for class 'environment':
     as.list(x, all.names = FALSE, ...)
     as.pairlist(x)

     is.list(x)
     is.pairlist(x)

     alist(...)

_A_r_g_u_m_e_n_t_s:

     ...: objects.

       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.

_D_e_t_a_i_l_s:

     Most lists in R internally are _Generic Vectors_, whereas
     traditional _dotted pair_ lists (as in LISP) are available but
     rarely seen by users (except as '\list{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 list type. For
     functions, this returns the concatenation of the list of formal
     arguments and the function body.  For expressions, the list of
     constituent calls is returned.

     'is.list' returns 'TRUE' iff its argument is a 'list' _or_ a
     'pairlist' of 'length' > 0. 'is.pairlist' returns 'TRUE' iff the
     argument is a pairlist or 'NULL' (see below).

     'is.list' and 'is.pairlist' are generic: you can write methods to
     handle specific classes of objects, see InternalMethods.

     The '"environment"' 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.  The list is in no particular order (the order depends on
     the order of creation of objects and whether the environmnent is
     hashed).  No parent environments are searched.  (Objects copied
     are duplicated so this can be an expensive operation.)

     An empty pairlist, 'pairlist()' is the same as 'NULL'.  This is
     different from 'list()'.

_R_e_f_e_r_e_n_c_e_s:

     Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S
     Language_. Wadsworth & Brooks/Cole.

_S_e_e _A_l_s_o:

     'vector("list", length)' for creation of a list with empty
     components; 'c', for concatenation; 'formals'.

_E_x_a_m_p_l_e_s:

     # 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, ...=)
     f
     al

     ## environment->list coercion

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

