12

Is it possible to see the syntax error or runtime error line number (highlight also) generated after running the code in R studio?

I searched the options but couldn't find.

waheebyaqub
  • 293
  • 1
  • 5
  • 13
  • May be a duplicate of http://stackoverflow.com/questions/1445964/r-script-line-numbers-at-error because R language needs to support line numbers so that R Studio utilize it – Aleksandr Levchuk Feb 17 '16 at 03:32

1 Answers1

14

First, have a look at ?traceback.

There are many ways to debug R code/script. This is only one example.

In RStudio, from the Debug drop down menu option On Error, choose Error Inspector for (what I think is) the easiest debug mode for finding the line number of an error/bug. You can also choose Break in Code to show the highlighted line of an R script that contains the error.

When the error occurs, you can click either of the small areas marked Show Traceback and Rerun with Debug. The screen shot below shows the effect of clicking "Show Traceback" (hence it now says "Hide Traceback"). It tells me that the error occurred when R attempted to call sample (the third call). LENGTH had not yet been defined.

enter image description here

Rich Scriven
  • 97,041
  • 11
  • 181
  • 245
  • 9
    i did check the Error Inspector and ran my code but i don't see any Hide Traceback or Rerun with Debug. – waheebyaqub Apr 22 '14 at 17:41
  • Version 0.98.501 – © 2009-2013 , i think it is the latest – waheebyaqub Apr 22 '14 at 18:40
  • 1
    @waheebyaqub Same here, I can get a stacktrace using `traceback()`, but no line numbers or any reference to a source file, regardless of selected options in the `Debug` menu. Debugging this way seems ridiculously painful. `Version 1.1.456 – © 2009-2018 RStudio, Inc.` – Herbert Aug 08 '19 at 10:12
  • 3
    January 28, 2020 here now. RStudio IDE still has no built-in line numbers for error messages. This was requested in 2009 and here we are 11 years later, and it is still not built-in to the core of RStudio. RStudio is a poor environment for debugging. – Rich Lysakowski PhD Jan 28 '20 at 19:11