Skip to content
Back to formatted view

Raw Message

Message-ID: <6rogo0zit0.fsf@verdi.stat.wisc.edu>
Date: 1999-01-15T14:56:11Z
From: Douglas Bates
Subject: Transferring data from S+ to R
In-Reply-To: Simon Fear's message of "Fri, 15 Jan 1999 10:08:29 -0000"

>>>>> "Simon" == Simon Fear <fears at roycastle.liv.ac.uk> writes:

  Simon> Not that I have got it quite right yet though; I still
  Simon> haven't worked out how to make, for example,

  Simon> var1 <- rnorm(10000)

  Simon> not create a new instance, eating 10000 globs of memory,
  Simon> every time it is called within a loop;

I think if you make the construction look like

 var1 <- double(10000)
 for (i in 1:niter) {
   var1[] <- rnorm(10000)  # replacement rather than assignment
   ...
 }

you avoid the multiple copies.  I haven't tested this particular case
but the basic idea is that replacement of elements of a vector is done
in-place, if possible, and not be creating a new object.  Assignment
to a name will usually result in a new object being created in a way
that masks the previous objects with that name. 
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._