Can R Studio show me which line number in my code was called last when an error occurs?

Can R Studio show me which line number in my code was called last when an error occurs?

1 Like

When you get an error, usually you have a modal with two options in console: "Traceback" and "Rerun with debug".

If you choose "Rerun with debug", it'll show you the line where error was thrown. However, keep in mind that sometimes it'll be very deep in call stack and the actual error might come from multiple levels deep from your function. In that case, you can see traceback to understand which function that you've created started the call that eventually generated an error.

There are more things you can try and there is this webinar that might help you: https://www.rstudio.com/resources/videos/debugging-techniques-in-rstudio-amanda-gadrow-june-2018/

4 Likes

Do you know why this works sometimes and not other times?

I make the following setting:

Choose: Debug > On Error > Error Inspector

Effect:
It works great for two or three runs, but then it goes back to just printing an error.

Can you provide sample code that replicates this issue? (FAQ: What's a reproducible example (`reprex`) and how do I do one?). The RStudio IDE team would like to know if this is a bug, but need more info to replicate and diagnose the issue.

This doesn't work for me with RStudio v1.1.456

I've set
Debug/On Error/Break
in code and also
Tools/Global options/ unchecked 'Use debug error handler only when my code contains errors'

and whilst it does open up the deeply nested file (not my code) where the crash occurs it doesn't give me a line number for the offending line in my code.

I've been successfully getting line numbers for my errors since 1982 so it's frustrating that they seem so elusive in RStudio.

Surely it must be possible somehow?