Christoph
Christoph

Reputation: 7063

RStudio "next line" command in browser() does not work

I thought, that you can use the browser() command in RStudio to step through lines in code. In many cases this works. However, in R scripts it seems it does not work. Here is a minimal example (Just copy the following code in test.R):

print("1")
browser()
print("2")
wrong # Produces error, which can not be tracked using browser
print("3")

(R-3.3.0, RStudio 0.99.489).
Any help is appreciated!

Thanks to @Batanichek, the following script solves the problem:

{
print("1")
browser()
print("2")
wrong
print("3")
}

Upvotes: 3

Views: 1284

Answers (1)

Batanichek
Batanichek

Reputation: 7871

If i understand you right

You can pass all your script into {}

like

{
+ print("1")
+ browser()
+ print("2")
+ wrong # Produces error, which can not be tracked using browser
+ print("3")
+ }
[1] "1"
Called from: top level 
Browse[1]> n
debug at #4: print("2")
Browse[1]> n
[1] "2"
debug at #5: wrong
Browse[1]> n
Error: object 'wrong' not found

then run will stop at browser()

Or if source

source('~/.active-rstudio-document')
[1] "1"
Called from: eval(expr, envir, enclos)
Browse[1]> n
debug at ~/.active-rstudio-document#4: print("2")
Browse[2]> n
[1] "2"
debug at ~/.active-rstudio-document#5: wrong
Browse[2]> n
Error in eval(expr, envir, enclos) : object 'wrong' not found

Upvotes: 3

Related Questions