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)

