11gsconfig <- new.env(parent = emptyenv())
2+ gsconfig $ original.par <- par(no.readonly = TRUE )
3+
4+ # Question...how can I update the user's par?
25
36# ' @title Load gsplot config
47# '
@@ -22,13 +25,34 @@ loadConfig = function(filename) {
2225 }
2326
2427 graphTemplate <- yaml.load_file(filename )
25- if (.Device != " null device" ){
26- dev.off()
28+
29+ if (length(all.equal(gsconfig $ original.par , par(no.readonly = TRUE ))) > 1 ){
30+ par(gsconfig $ original.par )
2731 }
28-
2932 gsconfig $ options <- graphTemplate
3033}
3134
35+ # ' @title Load gsplot temporary config
36+ # '
37+ # ' @description Loads the config file into options which are
38+ # 'used elsewhere in the application. This will only change the config paremeters while
39+ # 'building up the gsplot object, not on print.
40+ # '
41+ # ' @param filename string to custom file
42+ # '
43+ # ' @importFrom graphics plot.xy
44+ # ' @importFrom graphics par
45+ # ' @importFrom yaml yaml.load_file
46+ # ' @importFrom grDevices dev.off
47+ load_temp_config = function (filename ) {
48+
49+ graphTemplate <- yaml.load_file(filename )
50+
51+ if (length(all.equal(gsconfig $ original.par , par(no.readonly = TRUE ))) > 1 ){
52+ par(gsconfig $ original.par )
53+ }
54+ gsconfig $ temp.config <- graphTemplate
55+ }
3256
3357
3458# ' @title Get configuration for gsplot
@@ -39,14 +63,15 @@ loadConfig = function(filename) {
3963# ' @param type string of gsplot config object to retrieve
4064# ' @param ... additional configuration to override what is pulled from config
4165# ' @param persist logical of whether to persist overrides to config
66+ # ' @param custom.config logical of whether to use default global (FALSE) or a config set for only one gsplot object
4267# '
4368# ' @examples
4469# ' config("par")
4570# '
4671# ' @importFrom graphics plot.xy
4772# ' @importFrom graphics par
4873# ' @export
49- config <- function (type , ... , persist = FALSE ){
74+ config <- function (type , ... , persist = FALSE , custom.config = FALSE ){
5075 allowedTypes <- names(pkg.env $ fun.details )
5176
5277 type <- match.arg(type , choices = allowedTypes )
@@ -55,7 +80,11 @@ config <- function(type, ..., persist=FALSE){
5580 loadConfig()
5681 }
5782
58- config_list <- gsconfig $ options
83+ if (custom.config ){
84+ config_list <- gsconfig $ temp.config
85+ } else {
86+ config_list <- gsconfig $ options
87+ }
5988
6089 globalConfig <- config_list [! (names(config_list ) %in% allowedTypes [allowedTypes != " par" ])]
6190
@@ -78,7 +107,7 @@ config <- function(type, ..., persist=FALSE){
78107
79108 if (persist ){
80109 if (type == " par" ){
81- gsconfig $ options [names(globalConfig )] <- globalConfig
110+ gsconfig $ options [names(globalConfig )] <- globalConfig
82111 } else {
83112 gsconfig $ options [[type ]] <- globalConfig
84113 }
0 commit comments