[Rd] An update method for lists?

Deepayan Sarkar deepayan.sarkar at gmail.com
Fri Sep 15 21:22:15 CEST 2006


Hi,

since lattice uses nested lists in various situations, it has had an
unexported function called updateList for a while, which looks like

> lattice:::updateList
function (x, val)
{
    if (is.null(x))
        x <- list()
    if (!is.list(x))
        stop("x must be NULL or a list")
    if (!is.list(val))
        stop("val must be a list")
    xnames <- names(x)
    for (v in names(val)) {
        existing <- v %in% xnames
        if (existing && is.list(x[[v]]) && is.list(val[[v]]))
            x[[v]] <- updateList(x[[v]], val[[v]])
        else x[[v]] <- val[[v]]
    }
    x
}

Basically, it recursively replaces elements that have been specified
in val, leaving the other components alone. I'm not aware of any other
actual situation where this is useful, but it certainly can be, so I
want to export this functionaliy. At least one other person (Gabor)
has also asked for that.

Now, as the name suggests, I think it might be reasonable to export
this as an update method for "list" objects. Depending on what others
(in particular r-core) think, one of these things might happen:

(1) I export it as updateList (or some other name) in lattice
(2) I export it as an S3 method update.list in lattice
(3) It gets added as an S3 method update.list in one of the base packages

The default option is (1), and I guess Sept 19 is the deadline for any
of these to be included in R 2.4.0.

Comments?

Deepayan




More information about the R-devel mailing list