[R] R: possibility for sth. like parameter passing by reference?
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Tue Feb 1 18:35:07 CET 2000
Thomas Lumley <thomas at biostat.washington.edu> writes:
> 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?
...
> 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.
Interesting... I would have expected that both functions would copy x
when the argument is evaluated, but the 2nd one create an additional
object the same size as x to hold the intermediate value of x+1.
I thought that the copying would be avoided altogether by using
h<-function(x)eval.parent(substitute(mean(x)+1))
but that seems to take as much space as g(), which seems to indicate
that the object is linked rather than copied in such cases.
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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