File: dendextend.R

package info (click to toggle)
r-cran-dendextend 1.19.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,076 kB
  • sloc: sh: 13; makefile: 2
file content (68 lines) | stat: -rw-r--r-- 1,970 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright (C) Tal Galili
#
# This file is part of dendextend.
#
# dendextend is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# dendextend is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
#  A copy of the GNU General Public License is available at
#  http://www.r-project.org/Licenses/
#








#' @title Convert dendrogram Objects to Class hclust
#' @description Convert dendrogram Objects to Class hclust while preserving
#' the call/method/dist.method values of the original hclust object (hc)
#' @export
#' @param x any object which has an as.hclust method.
#' (mostly used for dendrogram)
#' @param hc an old hclust object from which to re-use
#' the call/method/dist.method values
#' @param ... passed to as.hclust
#' @return An hclust object (from a dendrogram) with the original hclust
#' call/method/dist.method values
#' @seealso \link{as.hclust}
#' @examples
#' hc <- hclust(dist(USArrests[1:3, ]), "ave")
#' dend <- as.dendrogram(hc)
#'
#' as.hclust(dend)
#' as_hclust_fixed(dend, hc)
as_hclust_fixed <- function(x, hc, ...) {
  x <- as.hclust(x, ...)

  # these elements are removed after using as.hclust - so they have to be manually re-introduced into the object.
  if (!missing(hc)) {
    x$call <- hc$call
    x$method <- hc$method
    x$dist.method <- hc$dist.method
  }

  return(x)
}




# ' @export
# as.phylo <- function (x, ...)
# {
# if (length(class(x)) == 1 && class(x) == "phylo")
# return(x)
# UseMethod("as.phylo")
# }
#### This function is added in order to fix the Error of having this function missing in the namespace
#### There might be a better way to resolve it...