talgalili / dendextend

Extending R's Dendrogram Functionality
152 stars 28 forks source link

incompatibility of `dendextend::cutree` with `cluster` objects #90

Closed GillesSanMartin closed 5 years ago

GillesSanMartin commented 5 years ago

Loading dendextend causes cutree to return an error when applied on cluster obsjects (agnes, diana). This breaks some other packages like clValid.

Error in cutree.default(clusterObj, nc) : Function cutree is only available for hclust/dendrogram/phylo objects only.

See for example this SO question (with reproducible example) : https://stackoverflow.com/questions/52319709

Would it be possible to do something from dendextend to avoid that ?

talgalili commented 5 years ago

Hi @GillesSanMartin , I've just pushed a new version of dendextend.

Before the fix:

> library(cluster)
> a <- diana(votes.repub, metric = "manhattan", stand = TRUE)
> dendextend::cutree(a, k=3)
 Show Traceback

 Rerun with Debug
 Error in cutree.default(a, k=3) : 
  Function cutree is only available for hclust/dendrogram/phylo objects only. 

After the fix:

library(cluster)
a <- diana(votes.repub, metric = "manhattan", stand = TRUE)
dendextend::cutree(a, k= 3)

> dendextend::cutree(a, k= 3)
       Alabama         Alaska        Arizona       Arkansas     California       Colorado    Connecticut 
             1              2              3              1              3              3              3 
      Delaware        Florida        Georgia 
etc...

Please confirm that it works for you as well?

GillesSanMartin commented 5 years ago

Waouh that was quick ! It works indeed with the new dendextend 1.10.0 I will modify the SO answer to point to this better solution...

Thanks for the quick response and for developing such an excellent package !

talgalili commented 5 years ago

My pleasure, thanks for the bug report :)