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

local_options() evaluates error handler functions, fails to restore original handler #73

Closed
mtmorgan opened this issue May 28, 2018 · 0 comments · Fixed by #74
Closed

Comments

@mtmorgan
Copy link
Contributor

mtmorgan commented May 28, 2018

With

library(withr)
f <- function(...) { cat("f\n"); 1 }
options(error = f)
g <- function() {
    local_options(list( error = function(...) { cat("g\n"); 2 } ))
    3
}

the evaluation of f() can be seen by the side-effect

> g()                                     # side-effect
f
[1] 3

The failure to re-establish the original handler is seen with

> options("error")                        # local option not removed
$error
(function (...) 
{
    cat("g\n")
    2
})()

The problem is in the call to set_options when returning from g()

> withr:::set_options
function (new_options) 
{
    do.call(options, as.list(new_options))
}

where do.call() evaluates as.list(new_options).

The problem came up in the context of RUnit (setting the equivalent of f() to report the traceback on error) and batchtools @mllg playing the role of g()

> head(batchtools:::execJob.Job, 3)
1 function (job)                                            
2 {                                                         
3     local_options(list(error = function(e) traceback(2L)))
mtmorgan added a commit to mtmorgan/withr that referenced this issue Jun 1, 2018
- evaluates arguments, so in particular error = ... fails
- fixes r-lib#73
jimhester pushed a commit that referenced this issue Jun 4, 2018
- evaluates arguments, so in particular error = ... fails
- fixes #73
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant