[R] R: possibility for sth. like parameter passing by reference?

Thomas Lumley thomas at biostat.washington.edu
Tue Feb 1 17:29:59 CET 2000

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 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

More information about the R-help mailing list