Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you make R print more detailed error messages?

I've often been frustrated by R's cryptic error messages. I'm not talking about during an interactive session, I mean when you're running a script. Error messages don't print out line numbers, and it's often hard to trace the offending line, and the reason for the error (even if you can find the location).

Most recently my R script failed with the the incredibly insightful message: "Execution halted." The way I usually trace such errors is by putting a lot of print statements throughout the script -- but this is a pain. I sometimes have to go through the script line by line in an interactive session to find the error.

Does anyone have a better solution for how to make R error output more informative?

EDIT: Many R-debugging things work for interactive sessions. I'm looking for help on command-line scripts run through Rscript. I'm not in the middle of an R session when the error happens, I'm at the bash shell. I can't run "traceback()"

like image 409
nsheff Avatar asked Sep 20 '11 12:09

nsheff


People also ask

How do I see all warnings in R?

last_warnings() and last_messages() return a list of all warnings and messages that occurred during the last R command. global_entrace() must be active in order to log the messages and warnings. By default the warnings and messages are printed with a simplified backtrace, like last_error() .

How do I write an error message in R?

In base R, errors are signalled, or thrown, by stop() : f <- function() g() g <- function() h() h <- function() stop("This is an error!") f() #> Error in h(): This is an error!

How do you handle errors in R?

In R Programming, there are basically two ways in which we can implement an error handling mechanism. Either we can directly call the functions like stop() or warning(), or we can use the error options such as “warn” or “warning. expression”.

How do I not print an error message in R?

How do I suppress an error in R? The simplest way of handling conditions in R is to simply ignore them: Ignore errors with try() . Ignore warnings with suppressWarnings() . Ignore messages with suppressMessages() .


1 Answers

Try some of the suggestions in this post:

General suggestions for debugging in R

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

like image 106
Ari B. Friedman Avatar answered Oct 17 '22 22:10

Ari B. Friedman