tests/testthat/test-options.R

test_that("local_options lets you unset an option (#156)", {
  expect_true(is.null(getOption("x")))
  local({
    local_options(foo = "bar")
    expect_equal(getOption("foo"), "bar")
  })

  expect_true(is.null(getOption("x")))

  local({
    local_options(foo = "bar")
    expect_equal(getOption("foo"), "bar")
    local_options(foo = NULL)
    expect_true(is.null(getOption("x")))
  })
  expect_true(is.null(getOption("x")))
})

Try the withr package in your browser

Any scripts or data that you put into this service are public.

withr documentation built on Oct. 28, 2024, 5:07 p.m.