modifyList               package:utils               R Documentation

_R_e_c_u_r_s_i_v_e_l_y _M_o_d_i_f_y _E_l_e_m_e_n_t_s _o_f _a _L_i_s_t

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

     Modifies a possibly nested list recursively by changing a subset
     of elements at each level to match a second list.

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

     modifyList(x, val)

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

       x: a named 'list', possibly empty.

     val: a named list with components to replace corresponding
          components in 'x'.

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

     A modified version of 'x', with the modifications determined as
     follows (here, list elements are identified by their names). 
     Elements in 'val' which are missing from 'x' are added to 'x'. For
     elements that are common to both but are not both lists
     themselves, the component in 'x' is replaced by the one in 'val'. 
     For common elements that are both lists, 'x[[name]]' is replaced
     by 'modifyList(x[[name]], val[[name]])'.

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

     Deepayan Sarkar Deepayan.Sarkar@R-project.org

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

     foo <- list(a = 1, b = list(c = "a", d = FALSE))
     bar <- modifyList(foo, list(e = 2, b = list(d = TRUE)))
     str(foo)
     str(bar)

