[R] more environment questions

Edna Bell edna.bell01 at gmail.com
Tue Jul 29 18:29:27 CEST 2008


Is there a way to set the environment within a function,,  please?


On Tue, Jul 29, 2008 at 11:25 AM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> e1 <- ...
> creates a new environment e1
>
> environment(e1)
> does nothing
>
> print(environment(e1))
> print environment e1
>
> By the way, if you are doing a lot of manipulations of environments
> you might want to look at the proto package which reframes the
> whole thing in terms of object oriented programming.
>
> On Tue, Jul 29, 2008 at 12:12 PM, Edna Bell <edna.bell01 at gmail.com> wrote:
>> Hi R Gurus:
>>
>> Here is some code that I was experimenting with, please:
>>
>>> f1 <- function(x) {
>> + e1 <- new.env(parent=.GlobalEnv)
>> + environment(e1)
>> + print(environment())
>> + return(mean(x))
>> + }
>>> f1(1:15)
>> <environment: 0x02525444>
>> [1] 8
>>>
>>
>> My question:  why isn't the environment within the function set to e1, please?
>>
>> Thanks,
>> Edna Bell
>>
>> ______________________________________________
>> R-help at 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.
>>
>



More information about the R-help mailing list