unlist                 package:base                 R Documentation

_F_l_a_t_t_e_n _L_i_s_t_s

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

     Given a list structure 'x', 'unlist' simplifies it to produce a
     vector which contains all the atomic components which occur in
     'x'.

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

     unlist(x, recursive = TRUE, use.names = TRUE)

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

       x: A list or vector.

recursive: logical. Should unlisting be applied to list components of
          'x'?

use.names: logical. Should names be preserved?

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

     'unlist' is generic: you can write methods to handle specific
     classes of objects, see InternalMethods.

     If 'recursive = FALSE', the function will not recurse beyond the
     first level items in 'x'.

     'x' can be a vector, but then 'unlist' does nothing useful, not
     even drop names.

     By default, 'unlist' tries to retain the naming information
     present in 'x'. If 'use.names = FALSE' all naming information is
     dropped.

     Where possible the list elements are coerced to a common mode
     during the unlisting, and so the result often ends up as a
     character vector.

     A list is a (generic) vector, and the simplified vector might
     still be a list (and might be unchanged).  Non-vector elements of
     the list (for example language elements such as names, formulas
     and calls) are not coerced, and so a list containing one or more
     of these remains a list.  (The effect of unlisting an 'lm' fit is
     a list which has individual residuals as components,)

_V_a_l_u_e:

     A vector of an appropriate mode to hold the list components.

_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:

     'c', 'as.list'.

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

     unlist(options())
     unlist(options(), use.names=FALSE)

     l.ex <- list(a = list(1:5, LETTERS[1:5]), b = "Z", c = NA)
     unlist(l.ex, recursive = FALSE)
     unlist(l.ex, recursive = TRUE)

     l1 <- list(a="a", b=2, c=pi+2i)
     unlist(l1) # a character vector
     l2 <- list(a="a", b=as.name("b"), c=pi+2i)
     unlist(l2) # remains a list

