[R] A new environment within the main function

Duncan Murdoch murdoch.duncan at gmail.com
Sun Sep 21 22:08:00 CEST 2014


On 21/09/2014, 9:06 AM, billy am wrote:
> Hi Everyone ,
> 
> I am having an issue with the following code and would need kind assistant.
> 
> For a specific reason , I would need to create a new environment for
> variables within the function and use them and I am having issue with it on
> the project I am doing.
> 
> The issue is that no matter what I do , I am getting the following error on
> 
> "Error in eval(expr, envir, enclos) : object 'x3' not found"
> 
> and it is the x3 that is within the groupedData(y~-1 + x3 | g
> 
> and not in the data.frame

It's not at all clear what you are attempting to do, but there are a few
strange things in your code:

> 
> fun1 <- function()
> {
>   ee <- new.env()
>   t <- 10
>   x <- 5
>   g<- 8
> 
>   assign("x2",x,envir = as.environment(ee))

ee is already an environment; why use as.environment?

> 
>   x3 <- get("x2" , envir = as.environment(ee))

Ditto.

> 
>   if(t == 10)
>   {
>     if(g == 8)
>       {

What have those got to do with the problem of interest?  It's a good
idea to post "minimal" examples; distractions are distracting.

> 
>          data.fr <- groupedData(y~-1 + x3 | g,
>                     data=data.frame(y,x3,h, dummy))

What is groupedData?  We also ask for self-contained examples, and that
isn't in the default packages.  Are you talking about the function in
nlme?  If so, do you expect it to make use of ee?  It never sees ee.

And where does y come from?

Duncan Murdoch


>     }
> 
>   }
> 
> }
> 
> Thanks and Regards
> Billy
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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