[R] what's the meaning of these in R-lang?
ronggui
042045003 at fudan.edu.cn
Thu Nov 24 16:30:14 CET 2005
Thanks very much.
>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.
I think I get your point.
I would like to express what I think using the folloing code:
> debug(mean)
> mean(1:10)
debugging in: mean(1:10)
debug: UseMethod("mean")
Browse[1]> environment()
<environment: 0236EDA0> # the evaluation environment.
Browse[1]> parent.env(environment())
<environment: namespace:base> # the enclosure of the evaluation environment.
Browse[1]>
exiting from: mean(1:10)
[1] 5.5
> environment(mean)
<environment: namespace:base> # the environment of mean.
So what "# the enclosure of the evaluation environment." is always the same as "# the environment of function (here is mean)" .
Am I wrong again?
Regards!
>(The text is arguably imprecise: "evaluation environment of the
>enclosing function call" would be better, especially since
>environment(f) is something different.)
Yes,It's easier to understand by "evaluation environment of the
enclosing function call"
>
>--
> 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
= = = = = = = = = = = = = = = = = = = =
2005-11-24
------
Deparment of Sociology
Fudan University
My new mail addres is ronggui.huang at gmail.com
Blog:http://sociology.yculblog.com
More information about the R-help
mailing list