[R] What is the most efficient way to assign to PARTS of objects in other frames/environments?
oehl_list@gmx.de
oehl_list at gmx.de
Fri May 17 17:18:42 CEST 2002
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list