Stop an R program without error

前端 未结 9 1619
执笔经年
执笔经年 2020-12-01 10:35

Is there any way to stop an R program without error?

For example I have a big source, defining several functions and after it there are some calls to the functions.

9条回答
  •  天涯浪人
    2020-12-01 11:11

    Just return something at the line you want to quit the function:

    f <- function(x, dry=F) { 
       message("hi1")
       if (dry) return(x)
       message("hi2")
       x <- 2*x 
    }
    y1 <- f(2) # = 4 hi1 hi2
    y2 <- f(2, dry=T) # = 2 hi1
    

提交回复
热议问题