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 FIFO cleanup:
on.exit(after = FALSE)
. - Calling
sys.on.exit()
elsewhere than top-level didn't work. This
is needed for manual invokation 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 FIFO cleanup:
Breaking change
- When
source()
is used with a local environment, as opposed to
globalenv()
(the default), you now need to set
options(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 writes lines
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_()
now works even if withr isn't attached (#207). -
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.