[R] dump.frames & .Traceback information

Pikounis, Bill v_bill_pikounis at merck.com
Tue Apr 8 14:14:12 CEST 2003


Thanks to the nice examples shown on the ?dump.frames help page and to the
design of R, one can devise an error handling strategy when R is called
non-interactively to return run-time error information to a calling program
(e.g. CGI with Perl as the calling program).

So if I run R 1.6.2 under Linux with something like "R --vanilla --silent <
inputfile > outputfile" where no .RData has been previously created, and
there is an execution error, is it correct that:

1)  The object .Traceback will not be created and thus a traceback() call
included in an options("error") custom redefinition will always yield the
message "No traceback available?"

The more important second question for me comes from the following: Let us
say that I use dump.frames() in the custom error handler and create a
"last.dump" object of class "dump.frames". Then debugger() shows that
names(last.dump) will output a list of available environments to browse.  

2) Are the descriptive lines produced by names(last.dump) essentially the
same content that traceback() would give in the analogous *interactive*
execution of the same code?

A code snippet example is below.

Thanks very much in advance,
Bill 

Code example:

cmdline.errorhandler <- function() {
  dump.frames(to.file=FALSE)
  sink("results.Rerror")

  ## next 7 lines copied directly from debugger() body	
  if (length(msg <- attr(last.dump, "error.message"))) {
    cat("Message: ", msg, "\n")
  }
  n <- length(last.dump)
  calls <- names(last.dump)
  cat("Available environments had calls:\n")
  cat(paste(1:n, ": ", calls, sep = ""), sep = "\n")
  ##

  traceback() ## does not seem to find a .Traceback object	
  sink()
  save.image() ## saves last current state
  invisible()
}

options(error = quote({cmdline.errorhandler(); q()}))

----------------------------------------
Bill Pikounis, Ph.D.
Biometrics Research Department
Merck Research Laboratories
PO Box 2000, MailDrop RY84-16  
126 E. Lincoln Avenue
Rahway, New Jersey 07065-0900
USA

v_bill_pikounis at merck.com

Phone: 732 594 3913
Fax: 732 594 1565


------------------------------------------------------------------------------



More information about the R-help mailing list