Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breaking from function not loop in R

Tags:

r

break

Ok so I am writing a larger function that call a few functions.

The issue is that I need to break out of "function_inner" under certain logical conditions without breaking out of "function_outer". Break seems to work for loops, and stop, well it stops all functions... any ideas?

function_outer <- function(){

    beta =1
        function_inner <- function(beta){
        if (beta==1){?break?stop}
        print("Its not working")
         }
    return(beta)
}
like image 536
mmann1123 Avatar asked Feb 19 '12 20:02

mmann1123


1 Answers

Do you mean to return a value?

function_outer <- function(){

  beta =1
  function_inner <- function(beta){
    if (beta==1){ return("Inner beta is 1") }
    print("Its not working")
     }
  return(beta)
}
like image 110
Ari B. Friedman Avatar answered Sep 29 '22 22:09

Ari B. Friedman