Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Wed, 1 Sep 1999 22:13:09 +0200

>>>>> On Wed, 1 Sep 1999 14:14:18 +0100 (BST), Jonathan Rougier <J.C.Rougier@durham.ac.uk> said:

    JonR> Just to follow my previous suggestion to modify diag(), the code
    JonR> I suggested is vulnerable to matrices with dimnames(x) <-
    JonR> list(NULL, NULL), which does occasionally happen (it has just
    JonR> happened to me!), so the following would be better ...

    JonR> "diag" <-
    JonR> function (x = 1, nrow, ncol = n) 
    JonR> {
    JonR>   if (is.matrix(x) && nargs() == 1) {
    JonR>     md <- min(dim(x))
    JonR>     y <- c(x)[1 + 0:(md - 1) * (dim(x)[1] + 1)]
    JonR>     nms <- dimnames(x)
    JonR>     if (is.list(nms) && !any(sapply(nms, is.null)) &&
    JonR>         all(nms[[1]][1:md] == nms[[2]][1:md])) 
    JonR>         names(y) <- nms[[1]][1:md]
    JonR>     return(y)
    JonR>   }

    JonR> ... the rest as in the original function.  Cheers, Jonathan.

    JonR> Jonathan Rougier                       Science Laboratories
    JonR> Department of Mathematical Sciences    South Road
    JonR> University of Durham                   Durham DH1 3LE

Your proposal has been (slightly improved) and commited for 0.64.1 
(or tomorrow's snapshot of R-release).

NEWS has
    o	diag(x) now keeps names when appropriate and barfs when x is an array.

Thank you very much.	Martin

r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch