On Wed, May 20, 2009 at 7:21 AM, Paulo Grahl <pgr...@gmail.com> wrote:
> 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 > ? > A <- function(q) { print("calculating y") y <- q+1 function(x) print(paste("value of x:",x,"value of y:",y)) } > A(5) [1] "calculating y" function(x) print(paste("value of x:",x,"value of y:",y)) <environment: 0x07abe2a8> > A(5)(4) [1] "calculating y" [1] "value of x: 4 value of y: 6" > A5 <- A(5) [1] "calculating y" > A5(4) [1] "value of x: 4 value of y: 6" > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.