Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
895 views
in Technique[技术] by (71.8m points)

debugging - How to step through an R script from the beginning?

I want to step through an R script. I saw the "debug" command while searching for how to do this but that seems to only apply to functions. This script doesn't have any functions.

The "browser" command looked promising so I put "browser()" as the first line of my script but it didn't seem to do anything when I ran it.

How do I get the script to pause on the first line so I can step through it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I was racking my brain trying to figure this out (stepping through a script without a specific function to call) in RStudio's IDE Version 0.98.1102.

Solution for a new script in RStudio:

  1. Create a new R script (ctrl+shift+n)
  2. Enter code in the file
  3. Set a break point by
    • a) clicking left of the code line number where you want to set a break point (red dot) or
    • b) adding browser() to the code line where you want to set a break point
  4. Save the file
  5. Enter debugging mode and source the file by
    • a) checking the Source on Save box (above the Source window) and then saving the file,
    • b) clicking the Source button at the top-right of the Source window,
    • c) entering debugSource("<yourfilename>") + enter in the Console, or
    • d) entering ctrl+shift+s
  6. Go through the debugging process

For more steps on debugging in RStudio, see this help file (dated April 23, 2015 12:59).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...