Skip to content

Instantly share code, notes, and snippets.

@robertzk
Created January 19, 2016 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertzk/c3b322f1bb0bfbf88225 to your computer and use it in GitHub Desktop.
Save robertzk/c3b322f1bb0bfbf88225 to your computer and use it in GitHub Desktop.
Capture an R stack trace
capture_calls <- function(e) {
e$calls <- sys.calls()
signalCondition(e)
}
fn <- function(x) {
call_another_function(x + 1)
}
call_another_function <- function(y) {
call_yet_other_function(y + 2)
}
call_yet_other_function <- function(z) {
tryCatch(
withCallingHandlers(stop("Omg"), error = capture_calls),
error = identity
)
}
fn(1)
@robertzk
Copy link
Author

capture_calls <- function(e) {
  e$calls <- head(sys.calls(), -8)
  signalCondition(e)
}

fn <- function(x) {
  call_another_function(x + 1)
}

call_another_function <- function(y) {
  call_yet_other_function(y + 2)
}

call_yet_other_function <- function(z) {
  tryCatch(
    withCallingHandlers(stop("Omg"), error = capture_calls),
    error = identity
  )
}

fn(1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment