-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathconfig.R
More file actions
99 lines (84 loc) · 3.39 KB
/
config.R
File metadata and controls
99 lines (84 loc) · 3.39 KB
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
gsconfig <- new.env(parent = emptyenv())
#' @title Load gsplot config
#'
#' @description Loads the config file into options which are
#'used elsewhere in the application
#'
#' @param filename string to custom file
#'
#'@examples
#'loadConfig()
#'@export
#' @importFrom graphics plot.xy
#' @importFrom graphics par
#' @importFrom yaml yaml.load_file
loadConfig = function(filename) {
if(missing(filename)){
filename <- system.file("extdata", "default.yaml", package = "gsplot")
}
graphTemplate <- yaml.load_file(filename)
gsconfig$options <- graphTemplate
}
#' @title Get configuration for gsplot
#'
#' @description Gets config for gsplot, mostly used internally
#' but exposed for use by gsplot users
#'
#' @param type string of gsplot config object to retrieve
#' @param ... additional configuration to override what is pulled from config
#'
#' @examples
#' config("par")
#'
#' @importFrom graphics plot.xy
#' @importFrom graphics par
#' @export
config <- function(type, ...){
allowedTypes <- c("par","points","lines","axis","plot",
"abline","legend","title","text",
"mtext","grid","segments",
"error_bar","arrows","bgCol","callouts",
"rect", "polygon", "symbols",
"curve", "orderToPlot")
type <- match.arg(type, choices = allowedTypes)
if (is.null(gsconfig$options)) {
loadConfig()
}
config_list <- gsconfig$options
globalConfig <- config_list[!(names(config_list) %in% allowedTypes[allowedTypes != "par"])]
formalsNames <- names(formals(plot.xy))
formalsNames <- switch(type,
par=names(par(no.readonly = TRUE)),
axis=names(formals(graphics::axis)),
legend=names(formals(graphics::legend)),
abline=names(formals(graphics::abline)),
title=names(formals(graphics::title)),
text=names(formals(graphics::text)),
mtext=names(formals(graphics::mtext)),
grid=names(formals(graphics::grid)),
segments=names(formals(graphics::segments)),
error_bar=c('x', 'y', '...', 'y.high', 'y.low', 'x.high', 'x.low', 'epsilon'),
bgCol=names(formals(bgCol.default)),
callouts=names(formals(callouts.default)),
rect=names(formals(graphics::rect)),
polygon=names(formals(graphics::polygon)),
symbols=names(formals(graphics::symbols)),
curve=names(formals(graphics::curve)),
orderToPlot='order',
formalsNames)
formalsNames <- formalsNames[formalsNames != "..."]
globalConfig <- globalConfig[names(globalConfig) %in% formalsNames]
if(type %in% names(config_list)){
globalConfig[names(config_list[[type]])] <- NULL
globalConfig <- append(globalConfig, config_list[[type]])
}
# really goofy, but I couldn't find a way to test for list that doesn't fail when it is not a list
if (length(expand.grid(...)) > 0 && is.list(list(...)[[1]])){
globalConfig[names(...)] <- NULL
globalConfig <- append(globalConfig, ...)
} else {
globalConfig[names(list(...))] <- NULL
globalConfig <- append(globalConfig, list(...))
}
return(globalConfig)
}