Skip to content

withr 2.5.0

  • defer() and all local_*() functions now work when run inside of a .Rmd. The deferred expressions are executed when knitr exits.

  • defer() and local_ functions now work within source(). The deferred expressions are executed when source() exits.

  • with_() and local_() gain a get argument. Supply a getter function to create with and local functions that are robust to early exits.

    When supplied, this restoration pattern is used:

    old <- get()
    on.exit(set(old))
    set(new)
    action()

    Instead of:

    old <- set(new)
    on.exit(set(old))
    action()

    This ensures proper restoration of the old state when an early exit occurs during set() (for instance when a deprecation warning is caught, see #191).

  • These with_ and local_ functions are now robust to early exits (see next bullet):

    • _locale()
    • _envvar()
    • _libpaths()
    • _options()
    • _par()
    • _path()
    • _seed()
  • with_namespace() and local_namespace() now pass warn.conflicts to attach() (@kyleam, #185).

  • local_rng_version() and local_seed() no longer warn when restoring sample.kind to "Rounding" (#167).

  • with_seed() now preserves the current values of RNGkind() (#167).

  • with_collate() is no longer affected by the LC_COLLATE environment variable set to “C” (#179).

  • Local evaluations in the globalenv() (as opposed to top-level ones) are now unwound in the same way as regular environments.

  • local_tempfile() gains a lines argument so, if desired, you can pre-fill the temporary file with some data.

withr 2.4.3

CRAN release: 2021-11-30

withr 2.4.2

CRAN release: 2021-04-18

withr 2.4.1

CRAN release: 2021-01-26

  • Tests which require capabilities("cairo") are now skipped.

withr 2.4.0

CRAN release: 2021-01-16

withr 2.3.0

CRAN release: 2020-09-22

Deprecations

  • local_tempfile() argument new is deprecated, in favor of returning the path to the new tempfile. calls like local_tempfile("xyz") should be replaced with xyx <- local_tempfile() in your code (#141).

New features

Minor improvements and fixes

withr 2.2.0

CRAN release: 2020-04-20

withr 2.1.2

CRAN release: 2018-03-15

withr 2.1.1

CRAN release: 2017-12-19

  • Fixes test failures with testthat 2.0.0

  • with_file() function to automatically remove files.

withr 2.1.0

CRAN release: 2017-11-01

withr 2.0.0

CRAN release: 2017-07-28

  • Each with_ function now has a local_ variant, which reset at the end of their local scope, generally at the end of the function body.

  • New functions with_seed() and with_preserve_seed() for running code with a given random seed (#45, @krlmlr).

withr 1.0.2

CRAN release: 2016-06-20

  • with_makevars() gains an assignment argument to allow specifying additional assignment types.

withr 1.0.1

CRAN release: 2016-02-04

withr 1.0.0

CRAN release: 2015-09-23

  • First Public Release