Debian Codegraph @

R/dendextend.R

raw
1 # Copyright (C) Tal Galili
2 #
3 # This file is part of dendextend.
4 #
5 # dendextend is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # dendextend is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # A copy of the GNU General Public License is available at
16 # http://www.r-project.org/Licenses/
17 #
18
19
20
21
22
23
24
25
26 #' @title Convert dendrogram Objects to Class hclust
27 #' @description Convert dendrogram Objects to Class hclust while preserving
28 #' the call/method/dist.method values of the original hclust object (hc)
29 #' @export
30 #' @param x any object which has an as.hclust method.
31 #' (mostly used for dendrogram)
32 #' @param hc an old hclust object from which to re-use
33 #' the call/method/dist.method values
34 #' @param ... passed to as.hclust
35 #' @return An hclust object (from a dendrogram) with the original hclust
36 #' call/method/dist.method values
37 #' @seealso \link{as.hclust}
38 #' @examples
39 #' hc <- hclust(dist(USArrests[1:3, ]), "ave")
40 #' dend <- as.dendrogram(hc)
41 #'
42 #' as.hclust(dend)
43 #' as_hclust_fixed(dend, hc)
44 as_hclust_fixed <- function(x, hc, ...) {
45 x <- as.hclust(x, ...)
46
47 # these elements are removed after using as.hclust - so they have to be manually re-introduced into the object.
48 if (!missing(hc)) {
49 x$call <- hc$call
50 x$method <- hc$method
51 x$dist.method <- hc$dist.method
52 }
53
54 return(x)
55 }
56
57
58
59
60 # ' @export
61 # as.phylo <- function (x, ...)
62 # {
63 # if (length(class(x)) == 1 && class(x) == "phylo")
64 # return(x)
65 # UseMethod("as.phylo")
66 # }
67 #### This function is added in order to fix the Error of having this function missing in the namespace
68 #### There might be a better way to resolve it...