Skip to content

Instantly share code, notes, and snippets.

@jonovik
Created January 24, 2017 10:23
Show Gist options
  • Save jonovik/9fd3ef556f2780920dc30b40a6150003 to your computer and use it in GitHub Desktop.
Save jonovik/9fd3ef556f2780920dc30b40a6150003 to your computer and use it in GitHub Desktop.
# Save state on error to facilitate debugging
postmortem <- function() {
# SAVE TO SOMEWHERE BOTH YOU AND THE RUNNING PROGRAM HAVE ACCESS
save.image("postmortem.RData")
# Skip irrelevant levels of traceback, see the "If x is numeric" part of ?traceback.
traceback(3)
stop()
}
options(error=postmortem)
# Your code goes here
x <- 42
# Example of code that causes an error
glm()
# Profit: You can now, even in a new session,
# load(postmortem.RData)
# and you will see x = 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment