[Rd] An update method for lists?

From: Deepayan Sarkar <deepayan.sarkar_at_gmail.com>
Date: Fri 15 Sep 2006 - 19:22:15 GMT


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



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Sep 16 05:24:25 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 15 Sep 2006 - 20:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.