DEV Community

Lance Bachmeier
Lance Bachmeier

Posted on

When you don't know how to debug your R program

#r

I've watched new R users get tripped up by completely uninformative error messages again and again. It's one thing to fix bugs when you know what's wrong; it's something entirely different when you have no clue what's wrong or even where to look.

The magic that will point you in the right direction is

traceback()

Read through the output in reverse order. The first lines of output (which are at the bottom) are the first lines that were run. The last line (the one at the top) tells you where the error occurred. Bingo. Now you know where to start looking.

You might still not know what is wrong, but given the popularity of R, you can copy and paste the last line (or the last couple of lines) into Google, and it will point you to someone else that has gotten the same output.

This isn't magic pixie dust - it's programming, after all - but it almost always gives you enough information to at least get started on debugging.

Top comments (0)