Skip to content

Commit e839398

Browse files
author
Lindsay Carr
authored
Merge pull request #416 from ldecicco-USGS/master
Re-trying config branch
2 parents 745a3b0 + 565e642 commit e839398

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+278
-67
lines changed

R/abline.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#'
1717
#'
1818
#' @export
19+
#' @seealso \code{\link[graphics]{abline}}
1920
#' @examples
2021
#' gs <- gsplot()
2122
#' gsNew <- points(gs, y=1, x=2, col="blue", pch=18, legend.name="Points")

R/add_new_par.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
add_new_par <- function(object, field){
88
defaults <- list(c())
99
if (field == 'global'){
10-
defaults <- config('par')
10+
defaults <- config('par', custom.config = object[["global"]][["config"]][["config.file"]])
1111
}
1212
if ('par' %in% names(object[[field]]))
1313
stop('par in ', field, ' already exists, cannot add it.', call. = FALSE)

R/add_to_view.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ add_to_view <- function(object, call.args, side, where){
5757
#' @param fun.name the name of the rendering function
5858
#' @param \dots arguments to \code{fun.name} or an embedded function
5959
#' within it.
60+
#' @param custom.config logical to use custom or global config file
6061
#' @return list with arguments. List is named according to function
6162
#' names.
6263
#' @examples
@@ -70,14 +71,14 @@ add_to_view <- function(object, call.args, side, where){
7071
#' gsplot:::filter_arguments('points', x=1:5, y=1:5, xlim=c(0,10), ylim=c(0,10),
7172
#' callouts(labels=c(rep(NA, 4), "oh")))$extracted.args
7273
#' @keywords internal
73-
filter_arguments <- function(fun.name, ...){
74+
filter_arguments <- function(fun.name, ..., custom.config = FALSE){
7475
dots <- separate_args(...)
7576

7677
standard.eval.args <- standard_eval_arguments(dots$args)
7778
if (is.null(fun.name)){
7879
function.args <- NULL
7980
} else {
80-
function.args <- function_call_args(fun.name, standard.eval.args)
81+
function.args <- function_call_args(fun.name, standard.eval.args, custom.config = custom.config)
8182
}
8283

8384
option.args <- standard.eval.args[!names(standard.eval.args) %in% c("", names(function.args[[1]]))]
@@ -101,14 +102,16 @@ standard_eval_arguments <- function(.dots){
101102
#' get the arguments that go into the function call, stripping out others and adding config defaults
102103
#'
103104
#' @param fun.name the name of the rendering function
105+
#' @param custom.config logical whether or not to use custom.config or global config defaults
104106
#' @param .dots lazy_dots arguments
105107
#' @keywords internal
106-
function_call_args <- function(fun.name, all.args){
108+
function_call_args <- function(fun.name, all.args, custom.config=FALSE){
107109

108110
fun.defaults <- function_defaults(fun.name)
109111

110-
args <- set_args(fun.name, all.args, package=fun.defaults$package)
111-
call.args <- list(formal_arguments(args, fun.defaults$def.funs, keep.names = names(config(fun.name))))
112+
args <- set_args(fun.name, all.args, custom.config = custom.config, package=fun.defaults$package)
113+
call.args <- list(formal_arguments(args, fun.defaults$def.funs,
114+
keep.names = names(config(fun.name, custom.config = custom.config))))
112115
names(call.args) <- fun.name
113116
return(call.args)
114117
}

R/arrows.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' gsplot arrows
22
#'
3-
#' Creates an arrow pointing at a specified plot location. See \code{\link[graphics]{arrows}} for more details.
3+
#' Creates an arrow pointing at a specified plot location. See \code{\link[graphics]{arrows}} for more details.
44
#'
55
#' @param object gsplot object
66
#' @param \dots Further graphical parameters may also be supplied as arguments. See 'Details'.
@@ -14,6 +14,7 @@
1414
#' }
1515
#'
1616
#' @export
17+
#' @seealso \code{\link[graphics]{arrows}}
1718
#' @examples
1819
#' gs <- gsplot() %>%
1920
#' points( y=c(3,1,2), x=1:3, xlim=c(0,NA),ylim=c(0,NA),

R/axis.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#' }
1313
#'
1414
#' @rdname axis
15+
#' @seealso \code{\link[graphics]{axis}}
1516
#' @export
1617
#' @examples
1718
#' gs <- gsplot() %>%
@@ -68,7 +69,8 @@ axis.gsplot <- function(object, ..., n.minor=0, tcl.minor=0.15, reverse=NULL, ap
6869

6970
fun.name <- "axis"
7071

71-
user_args <- filter_arguments(fun.name = fun.name, ...)$call.args
72+
user_args <- filter_arguments(fun.name = fun.name, ...,
73+
custom.config = object[["global"]][["config"]][["config.file"]])$call.args
7274

7375
sides <- user_args[[fun.name]]$side
7476
user_args[[fun.name]]$side <- NULL

R/bgCol.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ bgCol <- function(object, ...) {
3636

3737
bgCol.gsplot <- function(object, ...){
3838

39-
to.gsplot <- filter_arguments(fun.name = "bgCol", ...)$call.args
39+
to.gsplot <- filter_arguments(fun.name = "bgCol", ...,
40+
custom.config = object[["global"]][["config"]][["config.file"]])$call.args
4041
object$global$bgCol <- append_replace(object$global$bgCol, to.gsplot[[1]])
4142
return(object)
4243

R/config.R

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
gsconfig <- 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
}

R/curve.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#' }
2424
#'
2525
#' @rdname curve
26+
#' @seealso \code{\link[graphics]{curve}}
2627
#' @export
2728
#' @importFrom lazyeval lazy lazy_eval
2829
#' @examples

R/gather_function_info.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#' @return a code{gsplot} object
2121
#' @keywords internal
2222
gather_function_info <- function(object, fun.name, ..., legend.name, side, where){
23-
arguments <- filter_arguments(fun.name, ..., side=side)
23+
arguments <- filter_arguments(fun.name, ..., custom.config = object[["global"]][["config"]][["config.file"]], side=side)
2424

2525
call.args <- arguments$call.args
2626
option.args <- arguments$option.args

R/grid.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#' @param \dots Further graphical parameters may also be supplied as arguments
77
#'
88
#' @export
9+
#' @seealso \code{\link[graphics]{grid}}
910
#' @examples
1011
#' gs <- gsplot()
1112
#' gsNew <- points(gs, y=1, x=2, xlim=c(0,NA),ylim=c(0,NA),
@@ -57,7 +58,7 @@ draw_custom_grid <- function(object, view.name){
5758

5859
view.name <- names(object[view.name])
5960

60-
grid.args <- set_args("grid", object[[view.name]][['grid']], package = "graphics")
61+
grid.args <- set_args("grid", object[[view.name]][['grid']],custom.config = object[["global"]][["config"]][["config.file"]], package = "graphics")
6162

6263
if (is.null(grid.args$nx)){
6364
x.side <- as.x_side_name(view.name)

0 commit comments

Comments
 (0)