File: dendextend_options.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 (163 lines) | stat: -rw-r--r-- 4,487 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# 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/
#







# create_dendextend_options <- function() {
#    # assigns the functions which could later be replaced by the FASTER dendextendRcpp functions
#
#
# }
# # create_dendextend_options()
# # dendextend_options
# # dendextend_options()





dendextend_options_env <- new.env()





#' @title Access to dendextend_options
#' @export
#' @description
#' This is a function inside its own environment. This enables a bunch of
#' functions to be manipulated outside the package, even when they are called
#' from function within the dendextend package.
#'
#'
#'
#' TODO: describe options.
#'
#' A new "warn" dendextend_options parameter. logical (FALSE). Should warning be issued?
#'
#' @author Kurt Hornik
#' @param option a character scalar of the value of the options we would
#' like to access or update.
#' @param value any value that we would like to update into the "option"
#' element in dendextend_options
#' @return a list with functions
#' @examples
#'
#' dendextend_options("a")
#' dendextend_options("a", 1)
#' dendextend_options("a")
#' dendextend_options("a", NULL)
#' dendextend_options("a")
#' dendextend_options()
dendextend_options <- local({
  options <- list()
  function(option, value) {
    #          ellipsis <- list(...)
    if (missing(option)) {
      return(options)
    }

    if (missing(value)) {
      options[[option]]
    } else {
      options[[option]] <<- value
    }
  }
}, envir = dendextend_options_env)
# a=2
# dendextend_options()
# dendextend_options(a=3)  # sadly, this will fail, and ellipsis does not help
# dendextend_options(a<-3)
# dendextend_options("a",3)
# dendextend_options("a")
# dendextend_options()




#' @title Populates dendextend functions into dendextend_options
#' @description
#' Populates dendextend functions into dendextend_options
#' @export
#' @return NULL
assign_dendextend_options <- function() {
  # assigns the functions which could later be replaced by the FASTER dendextendRcpp functions

  # dendextend_options("get_branches_heights" , dendextend::dendextend_get_branches_heights)
  # dendextend_options("heights_per_k.dendrogram" , dendextend::dendextend_heights_per_k.dendrogram)
  # dendextend_options("cut_lower_fun" , dendextend::dendextend_cut_lower_fun)
  # dendextend_options("labels.dendrogram" , dendextend::dendextend_labels.dendrogram)
  dendextend_options("warn", FALSE)
}

# dendextend_options("cut_lower_fun")
#










remove_dendextend_options <- function() {
  # assigns the functions which could later be replaced by the FASTER dendextendRcpp functions
  #    options(dendextend_get_branches_heights = NULL)
  #    options(dendextend_heights_per_k.dendrogram = NULL)
  #    options(dendextend_cut_lower_fun = NULL)
  #    rm(dendextend_options)

  # thid doesn't quite remove it - it just empties it.
  #    x <- names(dendextend::dendextend_options())
  #    for(i in x) dendextend::dendextend_options(i, NULL)

  # assign("options", list(), envir = dendextend_options_env)
}



#
#
# ## Too risky, leave as is...
#
# search()
# library(magrittr)
# dend <- USArrests %>% dist %>% hclust(method = "ave") %>% as.dendrogram
# dendextend::color_branches(dend, k = 2)
# search()
#
# dendextend::assign_dendextend_options()
# detach("package:dendextend")
# dendextend:::dendextend_options()
# dendextend:::remove_dendextend_options()
# ls(envir = dendextend:::dendextend_options_env)
# rm(list = ls(envir = dendextend:::dendextend_options_env))
# assign("options", list(), envir = dendextend:::dendextend_options_env)
# get("options", envir = dendextend:::dendextend_options_env)
# rm("options", envir = dendextend:::dendextend_options_env)
# dendextend::assign_dendextend_options()
# dendextend:::dendextend_options()
# ls(envir = dendextend:::dendextend_options_env)
# assign("options", NULL, envir = dendextend:::dendextend_options_env)
#