Skip to content
Back to formatted view

Raw Message

Message-ID: <755f575b0905200421g7f092a03gfdd85ce05ef6a81b@mail.gmail.com>
Date: 2009-05-20T11:21:49Z
From: Paulo Grahl
Subject: Functions returning functions

Dear All:

I have a question regarding the behavior of functions.
Say I define a function that returns another function :
A <- function(parameters) {
     # calculations w/ parameters returning 'y'
     tmpf <- function(x) { # function of 'y' }
     return(tmpf)
}

The value of the parameters are stored in an environment local to the
function. Then I call
x<- something
B<-A(x)

When R executes this last statement,  does it perform all the
calculations inside function A again (i.e., all the calculations that
yield 'y')
 or the value of 'y' is already stored in the function's local environment ?

Many thanks.
Paulo Gustavo Grahl, CFA