Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

line by line debugging in R studio

Tags:

r

rstudio

Is there a way to debug the code line by line in R studio environment ??

I know there are breakpoints, Next, continue etc to debug. But I am looking for a line by line debug option like the one in Visual Studio.

Thank you

like image 641
Lucky Avatar asked Mar 31 '15 00:03

Lucky


1 Answers

For R-Studio newbies like me that are used to other IDEs:

a) Set a break point by clicking on the border or pressing Shift+F9 (=>red break point dot is shown)

b) As equivalent to "Debug" in other IDEs:

  • Click source or
  • Press Ctrl+Shift+Enter or
  • Activate source on save and save

c) Have a look at the Console view. There are common debug options:

  • Execute Next Line F10
  • Step Into Function Shift+F4
  • Finish function Shift+F6
  • Continue Shift+F5
  • Stop Debugging Shift+F8

(Unfortunately I did not find a way to adapt the key shortcuts for those options. They are not listed under Tools=>Modify Keyboard shortcuts.)

enter image description here

d) There does not seem to be a "hover over expression" feature while debugging. You can have a look at the Environment view to see the value of a variable and use the Console to evaluate expressions while debugging.

If you want to run the script without debugging and without clearing the break points, select all lines Ctrl+A and use the Run button. (Seems to be complicated to me.... I would expect an extra run button or key shortcut for that but could not find one.)

If there is no selection, the Run button only executes the current line. You can press that button several times to step through the code and see the corresponding console output (=pseudo debugging).

Also see documentation at

  • https://support.rstudio.com/hc/en-us/articles/200484448-Editing-and-Executing-Code

  • https://support.rstudio.com/hc/en-us/articles/205612627-Debugging-with-RStudio

and related questions:

  • Disable all breakpoints in RStudio
  • Debugging a function in a different source file in R
  • Rstudio debug - missing step into button
  • https://support.rstudio.com/hc/en-us/community/posts/202156378-how-do-i-clear-the-console-
like image 84
Stefan Avatar answered Nov 02 '22 09:11

Stefan