Changelog
Source:NEWS.md
withr 3.0.2
CRAN release: 2024-10-28
-
local_language()
now never warns when set to"C"
(#254). This is a cross-platform and silent way of disablinggettext()
translations.
withr 3.0.0
CRAN release: 2024-01-16
Performance of withr
-
defer()
is now a thin wrapper aroundbase::on.exit()
. This is possible thanks to two contributions that we made to R 3.5:- We added an argument for LIFO cleanup:
on.exit(after = FALSE)
. - Calling
sys.on.exit()
elsewhere than top-level didn’t work. This is needed for manual invocation withdeferred_run()
.
Following this change,
defer()
is now much faster (although still slower thanon.exit()
which is a primitive function and about as fast as it gets). This also increases the compatibility ofdefer()
withon.exit()
(all handlers are now run in the expected order even if they are registered withon.exit()
) and standalone versions ofdefer()
. - We added an argument for LIFO cleanup:
Breaking change
- When
source()
is used with a local environment, as opposed toglobalenv()
(the default), you now need to setoptions(withr.hook_source = TRUE)
to get proper withr support (runningdefer()
orlocal_
functions at top-level of a script). This support is disabled by default in local environments to avoid a performance penalty in normal usage of withr features.
Other features and bugfixes
deferred_run()
now reports the number of executed expressions with a message.deferred_run()
can now be run at any point in a knitr file (#235).local_tempfile()
now writeslines
in UTF-8 (#210) and always uses\n
for newlines (#216).local_pdf()
and friends now correctly restore to the previously active device (#138).local_par()
andwith_par()
now work if you don’t set any parameters (#238).with_language()
now properly resets the translation cache (#213).Fixes for Debian packaging.
withr 2.5.0
CRAN release: 2022-03-03
defer()
and alllocal_*()
functions now work when run inside of a.Rmd
. The deferred expressions are executed when knitr exits.defer()
andlocal_
functions now work withinsource()
. The deferred expressions are executed whensource()
exits.-
with_()
andlocal_()
gain aget
argument. Supply a getter function to createwith
andlocal
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_
andlocal_
functions are now robust to early exits (see next bullet):_locale()
_envvar()
_libpaths()
_options()
_par()
_path()
_seed()
with_namespace()
andlocal_namespace()
now passwarn.conflicts
toattach()
(@kyleam, #185).local_rng_version()
andlocal_seed()
no longer warn when restoringsample.kind
to"Rounding"
(#167).with_seed()
now preserves the current values ofRNGkind()
(#167).with_collate()
is no longer affected by theLC_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
Lionel Henry is the new maintainer.
Handlers registered with the global environment (as happens when
local_()
is run at the top-level, outside a function) are now automatically run when the R session ends (#173).New
with_language()
andlocal_language()
to temporarily control the language used for translations (#180).with_seed()
now caches the check for R version, so is now faster (#170)with_makevars()
andlocal_makevars()
now eagerly evaluate thepath
argument (#169)
withr 2.4.2
CRAN release: 2021-04-18
local_options()
now lets you set an option toNULL
as intended (#156)local_tempfile()
argumentenvir
is deprecated, in favor of.local_envir
. All withr functions exceptlocal_tempfile()
used.local_envir
to specify environments, so this makes this function consistent with the rest. (#157)with_environment()
now passingpos
andwarn.conflicts
toattach()
, as intended (#161).with_seed()
now also sets the RNG via new arguments.rng_kind
,.rng_normal_kind
and.rng_sample_kind
(#162, @AshesITR).with_timezone()
now works after recent changes toSys.timezone()
in R-devel (#165)
withr 2.4.0
CRAN release: 2021-01-16
withr is now licensed as MIT (#154).
Tests for
with_cairo_pdf()
andwith_cairo_ps()
have been removed, as they fail if Cairo is not available, such as with M1 macOS systems (#158)local_seed()
is now exported (#153)
withr 2.3.0
CRAN release: 2020-09-22
Deprecations
-
local_tempfile()
argumentnew
is deprecated, in favor of returning the path to the new tempfile. calls likelocal_tempfile("xyz")
should be replaced withxyx <- local_tempfile()
in your code (#141).
New features
New
local_seed()
function andlocal_preserve_seed()
functions to correspond towith_seed()
andwith_preserve_seed()
(#139).New
local_tempdir()
function added to create a temp directory (#140)local_*()
functions now take dots (...
), which can simplify calls in some cases, e.g. you can now uselocal_options(foo = "bar")
rather thanlocal_options(c(foo = "bar"))
.
Minor improvements and fixes
defer()
now throws an error if an error occurs in the deferred expression (#148)with_file()
andlocal_file()
can now work if the file is actually a directory (#144).
withr 2.2.0
CRAN release: 2020-04-20
defer()
can set deferred events on.GlobalEnv
to facilitate the interactive development of code inside a function or test. Helpersdeferred_run()
(anddeferred_clear()
) provide a way to explicity run and clear (or just clear) deferred events (#76, @jennybc).with_connection()
now works when existing objects or connections exist with the same names (#120)with_makevars()
now usestools::makevars_user()
to determine the default user makevars file (#77, @siddharthab).with_options()
no longer usesdo.call()
, so optiosn are not evaluated on exit (#73, @mtmorgan).with_package()
no longer has thehelp
argument (#94, @wendtke).with_package()
now does not try to detach the package if it is already attached before callingwith_package()
(#107)with_preserve_seed()
now restores.Random.seed
if it is not set originally (#124).Add
with_rng_version()
andlocal_rng_version()
functions to change the version of the RNG (#90, @gaborcsardi).with_svg()
documentation now is consistent across R versions (#129)Add
with_timezone()
andlocal_timezone()
functions to change the time zone (#92, @gaborcsardi).with_tempfile()
andlocal_tempfile()
now delete recursively directories on exit (#84, @meta00).
withr 2.1.2
CRAN release: 2018-03-15
set_makevars()
is now exported (#68, @gaborcsardi).with_temp_libpaths()
gains anaction
argument, to specify how the temporary library path will be added (#66, @krlmlr).
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
with_connection()
function to automatically close R file connections.with_db_connection()
function to automatically disconnect from DBI database connections.with_gctorture2
command to run code with gctorture2, useful for testing (#47).with_package()
,with_namespace()
andwith_environment()
(and equivalent locals) functions added, to run code with a modified object search path (#38, #48).Add
with_tempfile()
andlocal_tempfile()
functions to create temporary files which are cleanup up afterwards. (#32)Remove the
code
argument fromlocal_
functions (#50).
withr 2.0.0
CRAN release: 2017-07-28
Each
with_
function now has alocal_
variant, which reset at the end of their local scope, generally at the end of the function body.New functions
with_seed()
andwith_preserve_seed()
for running code with a given random seed (#45, @krlmlr).
withr 1.0.2
CRAN release: 2016-06-20
-
with_makevars()
gains anassignment
argument to allow specifying additional assignment types.
withr 1.0.1
CRAN release: 2016-02-04
- Relaxed R version requirement to 3.0.2 (#35, #39).
- New
with_output_sink()
andwith_message_sink()
(#24).