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

Skip needs to capture context #352

Closed
hadley opened this issue Jan 26, 2016 · 4 comments
Closed

Skip needs to capture context #352

hadley opened this issue Jan 26, 2016 · 4 comments

Comments

@hadley
Copy link
Member

hadley commented Jan 26, 2016

I think we need something like:

skip <- function(message, call = sys.call()) {
  cond <- structure(list(message = message, call = call), class = c("skip", "condition"))
  stop(cond)
}
@hadley
Copy link
Member Author

hadley commented Jan 26, 2016

And then we need a standard way of extracting the file name and line number from skip(), error() and warning().

@hadley
Copy link
Member Author

hadley commented Jan 26, 2016

Looks like the context is lost if call. = FALSE:

str(tryCatch({
  f <- function() stop("Hi!", call. = FALSE)
  f()
}, error = function(e) {
    e

  }

))

@krlmlr
Copy link
Member

krlmlr commented Jan 30, 2016

The context is available e.g. in our capture_calls() function, even with call. = FALSE. No need to modify skip(), we can simply install a handler here.

tryCatch(
  withCallingHandlers(
    stop("a", call. = FALSE),
    error = function(e) print(sys.calls())),
  error = function(e) NULL)

This would be also the way to go for #356: Simply call recover() in the calling handler (and use conditions for indicating test failues, #215 (comment)).

@hadley
Copy link
Member Author

hadley commented Feb 18, 2016

@krlmlr ok, makes sense.

@hadley hadley closed this as completed Feb 18, 2016
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

No branches or pull requests

2 participants