From suharto_anggono at yahoo.com  Sat Feb 13 17:31:55 2016
From: suharto_anggono at yahoo.com (Suharto Anggono Suharto Anggono)
Date: Sat, 13 Feb 2016 16:31:55 +0000 (UTC)
Subject: [Rd] Show rapply(how="replace") as alternative to 'dendrapply' to
 change leaves?
References: <537067577.2937161.1455381115574.JavaMail.yahoo.ref@mail.yahoo.com>
Message-ID: <537067577.2937161.1455381115574.JavaMail.yahoo@mail.yahoo.com>

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")



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