# NOT RUN {
dend <- USArrests[1:4, ] %>%
dist() %>%
hclust() %>%
as.dendrogram()
order.dendrogram(dend) # c(4L, 3L, 1L, 2L)
# Watch this!
dend_changed <- dend
dend_changed <- rev(dend_changed)
expect_false(identical(order.dendrogram(dend_changed), order.dendrogram(dend)))
# we keep the order of dend_change, so that the leaves order are synced
# with their labels JUST LIKE dend:
old_dend_changed_order <- order.dendrogram(dend_changed)
# now we change dend_changed leaves order values:
order.dendrogram(dend_changed) <- 1:4
# and we can fix them again, based on their old kept leaves order:
dend_changed <- match_order_dendrogram_by_old_order(
dend_changed, dend,
old_dend_changed_order
)
expect_identical(order.dendrogram(dend_changed), order.dendrogram(dend))
# }
Run the code above in your browser using DataLab