Debugger doesn't stop at breakpoint

I run into the same debugger issue (post) for RStudio v1.3.1073-1 Preview. The following is the runnable example that I re-post here. It seems not solved for a long time.

Save1.R and source 2.R. Then set a breakpoint at nethermost x (around Line 30) in 2.R. Run "test(2)" in 1.R. You'll see debugger does not stop at the breakpoint. But funny that it can stop before the "if else".

Why does Rstudio not stop at 'x'?

For 1.R, the code is

source("2.R")
test(2)

For 2.R, the code is



    test <- function(x){

    if (is.null(x) & is.null(x)){
    stop("Stop")
    }

    ######################## Empirical Histogram ############################

    if (x > 1){
    #########################################################
    #########################################################
    #########################################################
    print("Hi")
    }else if (x<0){
    #########################################################
    #########################################################
    #########################################################
    print("yes")
    }else{
    #########################################################

    #########################################################

    #########################################################
    print("no")

    }

    x

    }

Hi @genwei007,

The function doesn't stop at the stop("Stop") because the conditional statement of if (is.null(x) & is.null(x)) is FALSE for test(2) so that part of the code is skipped. The stop() code will only run if the input x is NULL. See code below:

test <- function(x){
  
  if (is.null(x) & is.null(x)){
    stop("Stop")
  }
  
  if (x > 1){
    print("Hi")
  }else if (x<0){
    print("yes")
  }else{
    print("no")
  }
  x
}

test(2)
#> [1] "Hi"
#> [1] 2
test(NULL)
#> Error in test(NULL): Stop

Created on 2020-08-11 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.