[R] A new environment within the main function

David Winsemius dwinsemius at comcast.net
Mon Sep 22 00:48:39 CEST 2014


On Sep 21, 2014, at 6: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
>
> fun1 <- function()
> {
>  ee <- new.env()
>  t <- 10
>  x <- 5
>  g<- 8
>
>  assign("x2",x,envir = as.environment(ee))
>
>  x3 <- get("x2" , envir = as.environment(ee))
>
>  if(t == 10)
>  {
>    if(g == 8)
>      {
>
>         data.fr <- groupedData(y~-1 + x3 | g,
>                    data=data.frame(y,x3,h, dummy))
>    }
>
>  }
>
> }

I don't get that error;  I get the perfectly understandable error:

 > fun1()
Error in data.frame(y, x3, h, dummy) : object 'y' not found

And if you create a `y` variable I would expect both h and dummy to be  
"not found" as well.


>
> 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.

David Winsemius, MD
Alameda, CA, USA



More information about the R-help mailing list