Skip to content

Commit 05716fb

Browse files
author
Jordan S Read
committed
Merge pull request #300 from jiwalker-usgs/persist_config
Adding a persist parameter
2 parents 90d5c6d + fa877aa commit 05716fb

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

R/config.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ loadConfig = function(filename) {
3131
#'
3232
#' @param type string of gsplot config object to retrieve
3333
#' @param ... additional configuration to override what is pulled from config
34+
#' @param persist logical of whether to persist overrides to config
3435
#'
3536
#' @examples
3637
#' config("par")
3738
#'
3839
#' @importFrom graphics plot.xy
3940
#' @importFrom graphics par
4041
#' @export
41-
config <- function(type, ...){
42+
config <- function(type, ..., persist=FALSE){
4243
allowedTypes <- c("par","points","lines","axis","plot",
4344
"abline","legend","title","text",
4445
"mtext","grid","segments",
@@ -95,5 +96,13 @@ config <- function(type, ...){
9596
globalConfig <- append(globalConfig, list(...))
9697
}
9798

99+
if (persist){
100+
if (type == "par"){
101+
gsconfig$options[names(globalConfig)] <- globalConfig
102+
} else {
103+
gsconfig$options[[type]] <- globalConfig
104+
}
105+
}
106+
98107
return(globalConfig)
99108
}

man/config.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/tests-config.R

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
context("config")
22

3+
cleanup <- function() {
4+
loadConfig()
5+
}
6+
37
test_that("lists and named args are identical", {
48
expect_equal(gsplot:::config("par",list("mar"=c(1,2,3,4)))$mar, c(1,2,3,4))
59
expect_equal(gsplot:::config("par",mar=c(1,2,3,4))$mar, c(1,2,3,4))
610
})
711

812
test_that("empty sets on gsplot are ignored",{
913
expect_is(gsplot:::config("par"), 'list')
10-
})
14+
})
15+
16+
test_that("persisting to config alters environment", {
17+
gsplot:::config("par", tcl=0.5, persist=TRUE)
18+
gsplot:::config("points", col="blue", persist=TRUE)
19+
expect_equal(gsplot:::config("par")$tcl, 0.5)
20+
expect_equal(gsplot:::config("points")$col, "blue")
21+
cleanup()
22+
})

0 commit comments

Comments
 (0)