Marcus Eger
2000-Feb-01 11:01 UTC
[R] R: possibility for sth. like parameter passing by reference?
Hello, is there a possibility to pass parameters to a function without copying them into the new environment? In my case I have huge data structures which I would not like to be copied - or handled globally. Thanks M. Eger -- +------------------------------------------------------- | E-Mail: marcus.eger at physik.uni-marburg.de +------------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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
2000-Feb-01 16:29 UTC
[R] R: possibility for sth. like parameter passing by reference?
On Tue, 1 Feb 2000, Marcus Eger wrote:> Hello, > is there a possibility to pass parameters to a > function without copying them into the new environment? > In my case I have huge data structures which I would not > like to be copied - or handled globally.In general objects are copied only when they are modified. The underlying code basically does call by reference until you change the object. There isn't a simple way to modify without copying, if that's what you mean. For example, if I define x to be a really big matrix and then R> g<-function(x) mean(x)+1 R> f<-function(x) mean(x+1) R> g(w) [1] 0.9992614 R> f(w) Error: heap memory (6144 Kb) exhausted [needed 1562 Kb more] The first function doesn't copy x, the second does. -thomas Thomas Lumley Assistant Professor, Biostatistics 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._