Rev 39397 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{modifyList}\alias{modifyList}\title{Recursively Modify Elements of a List}\description{Modifies a possibly nested list recursively by changing a subset ofelements at each level to match a second list.}\usage{modifyList(x, val)}\arguments{\item{x}{a named \code{\link{list}}, possibly empty.}\item{val}{a named list with components to replace correspondingcomponents in \code{x}.}}\value{A modified version of \code{x}, with the modifications determined asfollows (here, list elements are identified by their names). Elementsin \code{val} which are missing from \code{x} are added to \code{x}.For elements that are common to both but are not both liststhemselves, 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]])}.}\examples{foo <- list(a = 1, b = list(c = "a", d = FALSE))bar <- modifyList(foo, list(e = 2, b = list(d = TRUE)))str(foo)str(bar)}\author{ Deepayan Sarkar \email{Deepayan.Sarkar@R-project.org}}\keyword{utilities}