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)

