[Rd] Show rapply(how="replace") as alternative to 'dendrapply' to change leaves?

Suharto Anggono Suharto Anggono suharto_anggono at yahoo.com
Sat Feb 13 17:31:55 CET 2016


A non-leaf dendrogram object in R is a list, possibly nested. In R-devel, rapply() preserves attributes on the list when how = "replace". So, the result of applying rapply(how = "replace") to such a dendrogram object is a dendrogram object. Usually, non-list components of such a dendrogram object are the leaves. So, rapply(how = "replace") can be used to change leaves only of such a dendrogram object. For such case, it is an alternative to 'dendrapply'.

How about showing it in the documentation? In particular, in examples for 'dendrapply', creation of 'dL' can alternatively use something like the following.
     local({
       colLabLeaf <<- function(n) {
           a <- attributes(n)
           i <<- i+1
           attr(n, "nodePar") <-
               c(a$nodePar, list(lab.col = mycols[i], lab.font = i%%3))
           n
       }
       mycols <- grDevices::rainbow(attr(dhc21,"members"))
       i <- 0
      })
     dL <- rapply(dhc21, colLabLeaf, how = "replace")



More information about the R-devel mailing list