tf <- tempfile()
dists <- matrix(c(0, 10, 20, 10, 0, 5, 20, 5, 0),
nrow=3,
dimnames=list(c("dog", "elephant", "horse")))
dend1 <- IdClusters(dists, method="NJ", asDendrogram=TRUE)
WriteDendrogram(dend1, file=tf)
dend2 <- ReadDendrogram(tf)
layout(matrix(1:2))
plot(dend1, main="Dendrogram Written")
plot(dend2, main="Dendrogram Read")
# Note that the ordering information is lost
any(unlist(dend1) != unlist(dend2)) # TRUE
unlink(tf)
Run the code above in your browser using DataLab