subListExtract            package:Biobase            R Documentation

_E_x_t_r_a_c_t _t_h_e _s_a_m_e _e_l_e_m_e_n_t _f_r_o_m _t_h_e _s_u_b_l_i_s_t_s _o_f _a _l_i_s_t

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

     Given a list of lists, this function can be used to extract a
     named element from each sublist.

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

     subListExtract(L, name, simplify = FALSE, keep.names = TRUE)

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

       L: A list of named lists

    name: The name of the element in the sublists that should be
          extracted.  This should be a length one character vector.

simplify: When 'TRUE', the return value will be an atomic vector.  If
          any extracted sublist value has length not equal to one and
          'simplify=TRUE', an error will be raised.  When 'FALSE', a
          list is returned containing the extracted elements.

keep.names: If 'TRUE' (default), the names of 'L' will be attached to
          the returned vector.

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

     This function is implemented in C and is intended to be faster
     than calling 'lapply' or 'sapply'.

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

     If 'simplify=FALSE', a list will be returned having the same
     length as 'L', but with each element containing the element named
     'name' from the corresponding inner list of 'L'.

     When 'simplify=TRUE', an atomic vector will be returned containing
     the extracted elements.  If any of the inner list elements do not
     have length one or cannot be put inside an atomic vector, an error
     will be raised.

_A_u_t_h_o_r(_s):

     Seth Falcon

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

     list_size = 500000
     innerL = list(foo="foo", bar="bar")
     L = rep(list(innerL), list_size)

     system.time({j0 = sapply(L, function(x) x$foo)})
     system.time({j1 = subListExtract(L, "foo", simplify=TRUE)})
     stopifnot(all.equal(j0, j1))

     LS = L[1:3]
     names(LS) = LETTERS[1:3]
     subListExtract(LS, "bar", simplify=TRUE)
     subListExtract(LS, "bar", simplify=FALSE)
     subListExtract(LS, "bar", simplify=TRUE, keep.names=FALSE)

