Can you make R print more detailed error messages? Can you make R print more detailed error messages? r r

Can you make R print more detailed error messages?


Try some of the suggestions in this post:

General suggestions for debugging in R

Specifically, findLineNum() and traceback()/setBreakpoint().


@Nathan Well add this line sink(stdout(), type="message") at the beginning of the script and you should get in console message both script content and output along with error message so you can see it as in interactive mode in the console. (you can then also redirect to a log file if you prefer keeping the console "clean")


Have a look at my package tryCatchLog (https://github.com/aryoda/tryCatchLog).

While it is impossible to improve the R error messages directly you can save a lot of time by identifying the exact code line of the error and have actual variables at the moment of the error stored in a dump for "post mortem" analysis!

The main advantages of the tryCatchLog function over tryCatch are

  • easy logging of errors, warnings and messages into a file or console
  • warnings do not stop the program execution (tryCatch stops the execution if you pass a warning handler function)
  • identifies the source of errors and warnings by logging a stack trace with a reference to the source file name and line number (since traceback does not contain the full stack trace)
  • allows post-mortem analysis after errors by creating a dump file with all variables of the global environment (workspace) and each function called (via dump.frames) - very helpful for batch jobs that you cannot debug on the server directly to reproduce the error!