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


#1

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


#2

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/


#3

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.


#4

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.