[R] what's the meaning of these in R-lang?

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Nov 24 13:57:25 CET 2005


ronggui <042045003 at fudan.edu.cn> writes:

> In this case the environment contains the variables local to the
> function, and its enclosure is the environment of the enclosing
> function.(R-lang:p11)

Page number are of dubious value for documents in multiple formats. It
is page 5 in the PDF version on CRAN!

> 
> I want to know if the "enclosing function" means the closure of the
> function? for example ,if I call function mean(),and the create an
> environment,say e1,then the enclosure of e1 is the namespace of base
> package? Right?

No. A closure of a function is the function plus its environment. 

For "enclosing function", consider

f <- function() {
        print(environment())
        hello <- "Hi, babe!"
        g <- function() print(hello)
        g
}
myfun <- f() 
myfun()
environment(myfun)


The enclosing function of g, and hence of myfun, is f. The evaluation
environment of g has the evaluation environment of f as its enclosure. 

(The text is arguably imprecise: "evaluation environment of the
enclosing function call" would be better, especially since
environment(f) is something different.)

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-help mailing list