Search code examples
rdebuggingtraceback

R: Debugging and tracing messages?


Whereas options(warn=2) will prompt an error and hence enable debugging, I'm struggling with doing the same for messages.

For example, somewhere in my codebase, an unknown function seems to use jsonlite-package, which triggers the following message.

So my question is: Is there a convenient way to trace back the origins of messages?

Note: Using browser() doesn't seem to help, since messages are not shown in browser-mode.


Solution

  • You can use wrap your code in a call to withCallingHandlers to turn messages into errors:

    withCallingHandlers(
      message("example message"),
      message = function(m) stop(m)
    )
    #Error in message("example message") : example message