Debian Codegraph @

R/dendextend_options.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 # create_dendextend_options <- function() {
26 # # assigns the functions which could later be replaced by the FASTER dendextendRcpp functions
27 #
28 #
29 # }
30 # # create_dendextend_options()
31 # # dendextend_options
32 # # dendextend_options()
33
34
35
36
37
38 dendextend_options_env <- new.env()
39
40
41
42
43
44 #' @title Access to dendextend_options
45 #' @export
46 #' @description
47 #' This is a function inside its own environment. This enables a bunch of
48 #' functions to be manipulated outside the package, even when they are called
49 #' from function within the dendextend package.
50 #'
51 #'
52 #'
53 #' TODO: describe options.
54 #'
55 #' A new "warn" dendextend_options parameter. logical (FALSE). Should warning be issued?
56 #'
57 #' @author Kurt Hornik
58 #' @param option a character scalar of the value of the options we would
59 #' like to access or update.
60 #' @param value any value that we would like to update into the "option"
61 #' element in dendextend_options
62 #' @return a list with functions
63 #' @examples
64 #'
65 #' dendextend_options("a")
66 #' dendextend_options("a", 1)
67 #' dendextend_options("a")
68 #' dendextend_options("a", NULL)
69 #' dendextend_options("a")
70 #' dendextend_options()
71 dendextend_options <- local({
72 options <- list()
73 function(option, value) {
74 # ellipsis <- list(...)
75 if (missing(option)) {
76 return(options)
77 }
78
79 if (missing(value)) {
80 options[[option]]
81 } else {
82 options[[option]] <<- value
83 }
84 }
85 }, envir = dendextend_options_env)
86 # a=2
87 # dendextend_options()
88 # dendextend_options(a=3) # sadly, this will fail, and ellipsis does not help
89 # dendextend_options(a<-3)
90 # dendextend_options("a",3)
91 # dendextend_options("a")
92 # dendextend_options()
93
94
95
96
97 #' @title Populates dendextend functions into dendextend_options
98 #' @description
99 #' Populates dendextend functions into dendextend_options
100 #' @export
101 #' @return NULL
102 assign_dendextend_options <- function() {
103 # assigns the functions which could later be replaced by the FASTER dendextendRcpp functions
104
105 # dendextend_options("get_branches_heights" , dendextend::dendextend_get_branches_heights)
106 # dendextend_options("heights_per_k.dendrogram" , dendextend::dendextend_heights_per_k.dendrogram)
107 # dendextend_options("cut_lower_fun" , dendextend::dendextend_cut_lower_fun)
108 # dendextend_options("labels.dendrogram" , dendextend::dendextend_labels.dendrogram)
109 dendextend_options("warn", FALSE)
110 }
111
112 # dendextend_options("cut_lower_fun")
113 #
114
115
116
117
118
119
120
121
122
123
124 remove_dendextend_options <- function() {
125 # assigns the functions which could later be replaced by the FASTER dendextendRcpp functions
126 # options(dendextend_get_branches_heights = NULL)
127 # options(dendextend_heights_per_k.dendrogram = NULL)
128 # options(dendextend_cut_lower_fun = NULL)
129 # rm(dendextend_options)
130
131 # thid doesn't quite remove it - it just empties it.
132 # x <- names(dendextend::dendextend_options())
133 # for(i in x) dendextend::dendextend_options(i, NULL)
134
135 # assign("options", list(), envir = dendextend_options_env)
136 }
137
138
139
140 #
141 #
142 # ## Too risky, leave as is...
143 #
144 # search()
145 # library(magrittr)
146 # dend <- USArrests %>% dist %>% hclust(method = "ave") %>% as.dendrogram
147 # dendextend::color_branches(dend, k = 2)
148 # search()
149 #
150 # dendextend::assign_dendextend_options()
151 # detach("package:dendextend")
152 # dendextend:::dendextend_options()
153 # dendextend:::remove_dendextend_options()
154 # ls(envir = dendextend:::dendextend_options_env)
155 # rm(list = ls(envir = dendextend:::dendextend_options_env))
156 # assign("options", list(), envir = dendextend:::dendextend_options_env)
157 # get("options", envir = dendextend:::dendextend_options_env)
158 # rm("options", envir = dendextend:::dendextend_options_env)
159 # dendextend::assign_dendextend_options()
160 # dendextend:::dendextend_options()
161 # ls(envir = dendextend:::dendextend_options_env)
162 # assign("options", NULL, envir = dendextend:::dendextend_options_env)
163 #