RE: [R] how modify object in parent.env

From: Vadim Ogranovich <vograno_at_evafunds.com>
Date: Wed 09 Mar 2005 - 11:03:20 EST


Assign() re-binds the value, not modifies it (the latter is what I needed)

> -----Original Message-----
> From: McGehee, Robert [mailto:Robert.McGehee@geodecapital.com]
> Sent: Tuesday, March 08, 2005 3:48 PM
> To: Vadim Ogranovich; r-help@stat.math.ethz.ch
> Subject: RE: [R] how modify object in parent.env
>
> This isn't an environment problem. Assigning something to a
> get call doesn't make any sense. Use assign.
>
> > a <- 5
> > get("a") <- 10
> Error: couldn't find function "get<-"
>
> And from the ?assign help page, you can pick what environment
> you want to make the assignment. Just pick the parent environment.
>
>
> -----Original Message-----
> From: Vadim Ogranovich [mailto:vograno@evafunds.com]
> Sent: Tuesday, March 08, 2005 6:36 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] how modify object in parent.env
>
>
> Hi,
>
> Is it possible to modify an object in the parent.env (as opposed to
> re-bind)? Here is what I tried:
>
> > x = 1:3
> # try to modify the first element of x from within a new environment
> > local(get("x", parent.env(environment()))[1] <- NA)
> Error in eval(expr, envir, enclos) : Target of assignment expands to
> non-language object
>
> # On the other hand retrieval works just fine
> > local(get("x", parent.env(environment()))[1])
> [1] 1
>
> Thanks,
> Vadim
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Mar 09 11:10:10 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:41 EST