[R] Transferring data from S+ to R

Douglas Bates bates at stat.wisc.edu
Fri Jan 15 15:56:11 CET 1999


>>>>> "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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list