Faster Dendrogram Manipulation using 'Rcpp'

Offers faster manipulation of dendrogram objects in R. A dendrogram object in R is a list structure with attributes in its nodes and leaves. Working with dendrogram objects often require a function to recursively go through all (or most) element in the list object. Naturally, such function are rather slow in R, but can become much faster thanks to 'Rcpp'.


A dendrogram object in R are is a list structure with attributes in its nodes and leaves.

Working with dendrogram objects often require a function to recursively go through all (or most) element in the list object. Naturally, such function are rather slow in R, but can become much faster thank to Rcpp.

This package offers faster manipulation of dendrogram objects in R.

To install the stable version on CRAN:

install.packages('dendextendRcpp')

To install the cutting-edge GitHub version:

if (!require('devtools')) install.packages('devtools'); 
devtools::install_github('talgalili/dendextendRcpp')
library(dendextendRcpp)
 
hc <- hclust(dist(USArrests))
dend <- as.dendrogram(hc)
 
labels(dend)
 
require(microbenchmark)
microbenchmark(stats_labels.dendrogram(dend),
               dendextendRcpp::dendextendRcpp_labels.dendrogram(dend),
               times = 100)
# about 10-30 times faster. It is faster the larger the tree is.
 

You are welcome to:

  • dendextendRcpp_labels.dendrogram
  • cut_lower_fun
  • get_branches_heights
  • heights_per_k.dendrogram

Visit the Rcpp project!

  • http://www.rcpp.org/
  • http://gallery.rcpp.org/
  • http://cran.r-project.org/web/packages/Rcpp/index.html
  • http://dirk.eddelbuettel.com/code/rcpp.html
  • http://blog.r-enthusiasts.com/tag/rcpp/

Code of conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

News

Fixed:

  • "Possibly mis-spelled words in DESCRIPTION: Rcpp (3:45, 16:15)" - single quote Rcpp in the title and description.
  • The Title field should be in title case, current version then in title case: ‘Faster dendrogram manipulation using Rcpp’ ‘Faster Dendrogram Manipulation using Rcpp’
  • checking package namespace information ... NOTE Namespaces with empty importFrom: ‘Rcpp’ ‘dendextend’
  • checking top-level files ... NOTE Non-standard file/directory found at top level: ‘NEWS.md’

UPDATED R FUNCTIONS:

  • renamed: labels.dendrogram -> dendextendRcpp_labels.dendrogram
  • assign_dendextendRcpp_to_dendextend -
    • now loads into dendextend_options the dendextendRcpp_labels.dendrogram. This is intended to fix: "checking use of S3 registration ... WARNING Registered S3 method from a standard package overwritten by 'dendextendRcpp': method from labels.dendrogram stats"
    • Added "dendextend::" to fix: "no visible global function definition for 'dendextend_options'"
  • Fix various "no visible global function definition for"

OTHER NOTES:

  • Now works through "create_dendextend_options" (Thanks to suggestions by Kurt Hornik and Uwe Ligges).

UPDATED R DOCS:

  • Hiding {microbenchmark} from the docs (Props to Prof Brian Ripley), from the functions: dendextendRcpp_get_branches_heights, dendextendRcpp_heights_per_k.dendrogram, dendextendRcpp::labels.dendrogram

UPDATED DESCRIPTION:

  • Added dependency for R (>= 3.0.0)

UPDATED R FUNCTIONS:

  • renamed:
    • cut_lower_fun -> dendextendRcpp_cut_lower_fun
    • get_branches_heights -> dendextendRcpp_get_branches_heights
    • heights_per_k.dendrogram -> dendextendRcpp_heights_per_k.dendrogram

OTHER NOTES:

  • Now works through "create_dendextend_options" (Thanks to suggestions by Kurt Hornik and Uwe Ligges).
  • dendextendRcpp 0.5.0 is intended to be shipped to CRAN.

UPDATED R FUNCTIONS:

  • assign_dendextendRcpp_to_dendextend - Moved to passing the functions through "options" instead of through assignInNamespace.

OTHER NOTES:

  • Version 0.4.0 of dendextendRcpp will not be effective for versions of dendextend which are before 0.13.0 (however, it would also not conflict with them...)
  • dendextendRcpp 0.4.0 is intended to be shipped to CRAN.

UPDATED R FUNCTIONS:

  • assign_dendextendRcpp_to_dendextend - remove assign of old_ functions (we might as well just copy them manually)
  • old_* functions moved to the new imports_dendextend.r file

UPDATED Rcpp FUNCTIONS:

  • patches for Rcpp 0.11.0, using as to wrap some functions so that the package will compile. Props to Kevin Ushey!
  • changed .hpp -> .h (for portability issues, props to Kurt Hornik)

UPDATED DESCRIPTION:

OTHER NOTES:

  • dendextend 0.3.3 is intended to be shipped to CRAN. (first release!)

UPDATED R FUNCTIONS:

  • assign_dendextendRcpp_to_dendextend - remove require(dendextend)
  • stats:::labels.dendrogram -> stats_labels.dendrogram (in the new imports_stats.r file)

TESTS:

  • dendextend::: -> old_

DOCS:

  • Added aliases to: 'old_cut_lower_fun', 'old_get_branches_heights', 'old_heights_per_k.dendrogram'. Thus fixing "checking for missing documentation entries ... WARNING - Undocumented code objects:"
  • Fix: Codoc mismatches from documentation object 'labels.dendrogram'
  • cut_lower_fun - fix "cutree" links (to go to exact package)
  • Fix: Undocumented arguments in documentation object 'cut_lower_fun'
  • Rcpp_cut_lower -> dendextendRcpp::Rcpp_cut_lower
  • Undocumented code objects - added aliases

OTHER NOTES:

  • some minor updated to README.md

  • Fixed: cut_lower_labels -> cut_lower_fun

  • Added importFrom in order to fix "Packages in Depends field not imported from:"

  • dendextend 0.3.2 is intended to be shipped to CRAN. (first release! - failed after not working with Rcpp 0.11.0, though it did work for Rcpp 0.10.6)

UPDATED R FUNCTIONS:

  • assign_dendextendRcpp_to_dendextend
    • added old_cut_lower_fun
    • Fixed the assignment of "old_" to "make sense"... (they are now added to dendextendRcpp enviornment)

OTHER NOTES:

  • Fixed [email protected] in DESCRIPTION
  • Fixes to indentation and some Rcpp modified code

NEW R FUNCTIONS ADDED:

  • cut_lower_fun - overrides dendextend function - will give a 4-16 times faster cutree(h) function for R!

NEW RCPP FUNCTIONS ADDED:

  • Rcpp_cut_lower (+find_dend_for_height). This function changes the output of the nodes to be of dendrogram class which enables the fast operation of functions on them!

OTHER NOTES:

  • added zzz.r file - with code to override dendextend functions in case dendextendRcpp is loaded AFTER dendextend.
  • fixed Rcpp_labels_dendrogram works test - adjusting for the new "warn" parameter.

NEW R FUNCTIONS ADDED:

  • get_branches_heights - overrides dendextend function dendextend:::get_branches_heights function.
  • heights_per_k.dendrogram - gives a 10 to 130(!) faster loading times.

NEW RCPP FUNCTIONS ADDED:

  • get_height
  • push_back_heights
  • Rcpp_get_dend_heights
  • Rcpp_k_per_height
  • Rcpp_k_per_heights (plural)

OTHER NOTES:

  • Moved "is" function to a new file called "is_functions.cpp". Created a "is_functions.hpp" file for it, and made sure to call it from "labels_dendrogram.cpp"
  • moved labels.dendrogram to a new file labels_dendrogram.r

BUG FIXES

  • labels.dendrogram - now returns a label also if the tree is just a leaf.

THE PACKAGE IS NOW RENAMED:

  • from RcppDend to dendextendRcpp - in order to have it easier to remember (at least for me).

UPDATED FUNCTIONS:

  • labels.dendrogram - added warn=FALSE

BUG FIXES

  • Added missing rows from NAMESPACE (They were removed automatically due to a bug in roxygen2+Rstudio)

OTHER NOTES:

  • Added tests

NEW R FUNCTIONS ADDED:

  • labels.dendrogram - overrides R's default stats:::labels.dendrogram function.

NEW RCPP FUNCTIONS ADDED:

  • is_list
  • is_string
  • is_logical
  • is_leaf
  • get_label
  • push_back_labels
  • Rcpp_labels_dendrogram
  • Rcpp_count_leaves

OTHER NOTES:

  • First commit. Includes DESCRIPTION, a template for a basic test, a labels function, and this NEWS.
  • Check if we have any old_ that should be changed into dendextend_

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("dendextendRcpp")

0.6.1 by Tal Galili, 4 years ago


https://github.com/talgalili/dendextendRcpp/, http://cran.r-project.org/web/packages/dendextendRcpp/


Report a bug at https://github.com/talgalili/dendextendRcpp/issues


Browse source code at https://github.com/cran/dendextendRcpp


Authors: Tal Galili [aut, cre, cph] (http://www.r-statistics.com) , Romain Francois [ctb] , Dirk Eddelbuettel [ctb] , Kevin Ushey [ctb] , Yoav Benjamini [ths]


Documentation:   PDF Manual  


GPL-2 | GPL-3 license


Depends on Rcpp, dendextend

Suggests testthat, microbenchmark

Linking to Rcpp


Suggested by pergola.


See at CRAN