Skip to content
Prev 32047 / 63424 Next

linking environments

On 3/25/2009 11:47 AM, Joerg Betzin wrote:
You didn't use nested functions.  They would look like this:

  help1 <- function(){
      help2 <- function(){
          if (x == 1)
                  cat("Hello world x = 1")
      }

      x <- 1
      help2()
  }

Because help2 is now nested within help1, it can see all the local 
variables in help1, so things work with it done this way.

There are tricks to define help2 outside of help1 but allow it to see 
the variables within there, but I'd keep it simple and avoid them.

Duncan Murdoch