Skip to content

Commit

Permalink
Merge pull request #434 from krlmlr/with_options
Browse files Browse the repository at this point in the history
with_options works as expected
  • Loading branch information
hadley committed Mar 17, 2014
2 parents efc7644 + a6f08f9 commit b2686c9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NEWS.md
@@ -1,5 +1,9 @@
# devtools 1.4.1.99

* The `with_options` works as expected, used to throw an error when trying to
set an option.
(Thanks to @krlmlr, #434)

* In `build()`, use `--no-build-vignettes` (#391).

* Bump R dependency to 3.0.2.
Expand Down
6 changes: 5 additions & 1 deletion R/with.r
Expand Up @@ -146,9 +146,13 @@ with_lib <- with_something(set_lib)

# options --------------------------------------------------------------------

set_options <- function(new_options) {
do.call(options, as.list(new_options))
}

#' @rdname with_something
#' @export
with_options <- with_something(options)
with_options <- with_something(set_options)

# par ------------------------------------------------------------------------

Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-with.r
Expand Up @@ -31,3 +31,13 @@ test_that("with_envar respects suffix and prefix", {
expect_equal(nested("suffix", "suffix"), c("1 2"))
expect_equal(nested("suffix", "prefix"), c("2 1"))
})

test_that("with_options works", {
expect_that(getOption("scipen"), not(equals(999)))
expect_equal(with_options(c(scipen=999), getOption("scipen")), 999)
expect_that(getOption("scipen"), not(equals(999)))

expect_that(getOption("zyxxyzyx"), not(equals("qwrbbl")))
expect_equal(with_options(c(zyxxyzyx="qwrbbl"), getOption("zyxxyzyx")), "qwrbbl")
expect_that(getOption("zyxxyzyx"), not(equals("qwrbbl")))
})

0 comments on commit b2686c9

Please sign in to comment.