Skip to content

A new environment within the main function

4 messages · Duncan Murdoch, David Winsemius, billy am

#
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))
    }

  }

}

Thanks and Regards
Billy
#
On 21/09/2014, 9:06 AM, billy am wrote:
It's not at all clear what you are attempting to do, but there are a few
strange things in your code:
ee is already an environment; why use as.environment?
Ditto.
What have those got to do with the problem of interest?  It's a good
idea to post "minimal" examples; distractions are distracting.
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
#
On Sep 21, 2014, at 6:06 AM, billy am wrote:

            
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.
David Winsemius, MD
Alameda, CA, USA
#
Hi Everyone ,

Thanks for the input.



On Mon, Sep 22, 2014 at 6:48 AM, David Winsemius <dwinsemius at comcast.net>
wrote: