Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure global defers run on exit #173

Merged
merged 8 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# withr (development version)

* 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add the PR number here?


* `with_seed()` now caches the check for R version, so is now faster (#170)

* `with_makevars()` and `local_makevars()` now eagerly evaluate the `path` argument (#169)
Expand Down
2 changes: 2 additions & 0 deletions R/compat-defer.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ defer <<- defer <- function(expr, envir = parent.frame(), priority = c("first",
if (identical(envir, .GlobalEnv) && is.null(get_handlers(envir))) {
message(
"Setting deferred event(s) on global environment.\n",
" * Will be run automatically when session ends\n",
" * Execute (and clear) with `withr::deferred_run()`.\n",
" * Clear (without executing) with `withr::deferred_clear()`."
)
reg.finalizer(envir, function(env) deferred_run(env), onexit = TRUE)
}
invisible(
add_handler(
Expand Down