\HeaderA{modifyList}{Recursively Modify Elements of a List}{modifyList}
\keyword{utilities}{modifyList}
\begin{Description}\relax
Modifies a possibly nested list recursively by changing a subset of
elements at each level to match a second list.
\end{Description}
\begin{Usage}
\begin{verbatim}
modifyList(x, val)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] a named \code{\LinkA{list}{list}}, possibly empty.
\item[\code{val}] a named list with components to replace corresponding
components in \code{x}.
\end{ldescription}
\end{Arguments}
\begin{Value}
A modified version of \code{x}, with the modifications determined as
follows (here, list elements are identified by their names).  Elements
in \code{val} which are missing from \code{x} are added to \code{x}.
For elements that are common to both but are not both lists
themselves, the component in \code{x} is replaced by the one in
\code{val}.  For common elements that are both lists, \code{x[[name]]}
is replaced by \code{modifyList(x[[name]], val[[name]])}.
\end{Value}
\begin{Author}\relax
Deepayan Sarkar \email{Deepayan.Sarkar@R-project.org}
\end{Author}
\begin{Examples}
\begin{ExampleCode}
foo <- list(a = 1, b = list(c = "a", d = FALSE))
bar <- modifyList(foo, list(e = 2, b = list(d = TRUE)))
str(foo)
str(bar)
\end{ExampleCode}
\end{Examples}

