Skip to content

withr 2.5.0

Compare
Choose a tag to compare
@lionel- lionel- released this 03 Mar 22:16
· 88 commits to main since this release
  • 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.