Skip to content

Commit

Permalink
added .list argument to options_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
markvanderloo committed Nov 5, 2015
1 parent e3f53ec commit e0b9a80
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build/DESCRIPTION
@@ -1,7 +1,7 @@
Package: settings
Type: Package
Title: Software Option Settings Manager for R
Version: 0.2.4
Version: 0.2.5
Date: 2015-10-27
Author: Mark van der Loo
Maintainer: Mark van der Loo <mark.vanderloo@gmail.com>
Expand Down
3 changes: 3 additions & 0 deletions pkg/NEWS
@@ -1,3 +1,6 @@
version 0.2.5
- options_manager gained .list argument

version 0.2.4
- support for limiting option values
- option names that were not defined when creating the options manager are now ignored with a warning.
Expand Down
11 changes: 9 additions & 2 deletions pkg/R/options.R
Expand Up @@ -25,6 +25,8 @@
#'
#'
#' @param ... Comma separated \code{[name]=[value]} pairs. These will be the names and default values for your options manager.
#' @param .list optional List of \code{[name]=[value]} pairs. Will be concatenated with
#' arguments in \code{...}.
#' @param .allowed list of named functions that check an option (see 'checking options')
#'
#' @return A \code{function} that can be used as a custom options manager. It takes as arguments
Expand Down Expand Up @@ -62,9 +64,14 @@
#' Create a local, possibly altered copy: \code{\link{clone_and_merge}}
#'
#' @export
options_manager <- function(..., .allowed){
options_manager <- function(..., .list, .allowed){
stop_if_reserved(...)
.defaults <- list(...)
if (missing(.list)){
.list <- NULL
} else {
stopifnot(is.list(.list))
}
.defaults <- c(list(...),.list)
.op <- .defaults

.al <- list()
Expand Down
19 changes: 19 additions & 0 deletions pkg/tests/testthat/testOptions.R
Expand Up @@ -17,6 +17,25 @@ test_that("Setting/resetting options",{
expect_warning(opt(fu=1))
})

test_that("Setting/resetting options with .list argument",{
opt <- options_manager(.list=list(foo=1,bar=2))
expect_equal(opt(foo=3),list(foo=3,bar=2))
expect_equal(opt(),list(foo=3,bar=2))
expect_equal(reset(opt), list(foo=1,bar=2))
expect_equal(opt(),list(foo=1,bar=2))
expect_warning(opt(fu=1))
})

test_that("Setting/resetting options with mixed .list argument",{
opt <- options_manager(foo=1, .list=list(bar=2))
expect_equal(opt(foo=3),list(foo=3,bar=2))
expect_equal(opt(),list(foo=3,bar=2))
expect_equal(reset(opt), list(foo=1,bar=2))
expect_equal(opt(),list(foo=1,bar=2))
expect_warning(opt(fu=1))
})


context("Local options")

test_that("Cloning options",{
Expand Down

0 comments on commit e0b9a80

Please sign in to comment.