Edit: It seems that OP is working with a long script, in this case you only need to wrap the script part after quality control with
if (n >= 500) { .... long running code here }
If you exit the function , you probably just want return() , explicitly or implicitly.
For example, explicit double return
foo <- function(x) { if(x < 10) { return(NA) } else { xx <- seq_len(x) xx <- cumsum(xx) } xx
The term
return() means that the last line looks as if you did
return(xx) , but it’s a bit more efficient to refuse
return() .
Some consider using multiple incorrect return styles; in long functions, keeping track of where the exit function can become complex or error prone. Therefore, an alternative is to have a single return point, but change the returned object using the if () else () clause. Such a modification of foo() would be
foo <- function(x) {
Gavin Simpson Jul 24. '13 at 14:47 2013-07-24 14:47
source share