oehl_list@gmx.de
2002-May-17 15:18 UTC
[R] What is the most efficient way to assign to PARTS of objects in other frames/environments?
Can please someone familiar with the R internals explain on the following: PR#1434 from r-bugs clarifies that assign("a[1]", x, SomeOtherFrame) or assign("a$a", x, SomeOtherFrame) will NOT assign to an object 'a' in the other frame BUT create a new object called 'a[1]' resp. 'a$a'. This leads to the following question: what is the most efficient way to assign to PARTS of objects in other frames/environments? Any way I know appears to have some problems associated: # doing it locally involves several calls and probably copies the whole object local.copy <- get("a", SomeOtherFrame) local.copy$a <- x assign("a", local.copy, SomeOtherFrame) # using eval fails because x might be unknown in the other frame> t1 <- function(){+ # x is locally defined + x <- 9 + eval(parse(text="a$a <- x"), envir=globalenv()) + }> t1()Error in eval(expr, envir, enclos) : Object "x" not found For me, it would highly make sense, if assign("a[1]") WOULD parse "a[1]" and assign to a's part, as Martin expected it to do. The same applies to get("a[1]", SomeOtherFrame). BTW: this issue dates back to 1997, when I tried (for S+Version3) to implement a library "ref" that allows to access objects in other frames via "references". I would appreciate any clarification on this one. Best Jens Oehlschl?gel -- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thomas Lumley
2002-May-17 15:43 UTC
[R] What is the most efficient way to assign to PARTS of objects in other frames/environments?
On Fri, 17 May 2002 oehl_list at gmx.de wrote:> Can please someone familiar with the R internals explain on the following: > > PR#1434 from r-bugs clarifies that > > assign("a[1]", x, SomeOtherFrame) > > or > > assign("a$a", x, SomeOtherFrame) > > will NOT assign to an object 'a' in the other frame BUT create a new object > called 'a[1]' resp. 'a$a'. > > This leads to the following question: what is the most efficient way to > assign to PARTS of objects in other frames/environments? > > Any way I know appears to have some problems associated: > > # doing it locally involves several calls and probably copies the whole > object > local.copy <- get("a", SomeOtherFrame) > local.copy$a <- x > assign("a", local.copy, SomeOtherFrame) > > # using eval fails because x might be unknown in the other frame > > t1 <- function(){ > + # x is locally defined > + x <- 9 > + eval(parse(text="a$a <- x"), envir=globalenv()) > + } > > t1() > Error in eval(expr, envir, enclos) : Object "x" not found >Instead of assign("a$a",x,envir=SomeOtherFrame) you can do eval(substitute(a$a<-localx,localx=x),envir=SomeOtherFrame) -thomas Thomas Lumley Asst. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Maybe Matching Threads
- What is the most efficient way to assign to PARTS of obje cts in other frames/environments?
- Create an environment and assign objects to it in one go?
- Most efficient way to check the length of a variable mentioned in a formula.
- factors and characters when attaching data...
- polygon() draws non-transparent border, erase.screen draws non-transparent border (PR#1881)