Skip to content

Q: replacing elements in an array

4 messages · Brian Ripley, Laurent Gautier

#
On Tue, 13 Aug 2002, Laurent Gautier wrote:

            
I don't think so.  See do_subassign and descendants.  It contains

    /* If there are multiple references to an object we must */
    /* duplicate it so that only the local version is mutated. */
    /* This will duplicate more often than necessary, but saves */
    /* over always duplicating. */
    /* FIXME: shouldn't x be protected? */

    if (NAMED(CAR(args)) == 2)
	x = SETCAR(args, duplicate(CAR(args)));

Now coercion can force a copy, but starting from a numeric array I think
your example does not duplicate.  And I can prove it:
[1] 20000128
[1] 29028352
[1] 29028352

so there was never a second copy.
See above.  Do your own experiments / reading of code?
#
Dear all,


I have a question about the way the replacement of elements in an array
works in R (having a slight idea of the answer), and a question about
the way to achieve my goals.

If I have a 3 ways-array called 'a', the command

a[1, , ] <- rnorm(10)  # assumes the size matches

will result in having the whole object 'a' copied (since arrays are
just 'vectors with dimensions' in R) ... and at some point
two objects like 'a' will be in memory, right ? (this was the first
question).

I have rather large arrays, and I would like to modify some of their
elements in-situ (to save memory). Is there a way to do that ?


Thanks,






Laurent

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Tue, 13 Aug 2002, Laurent Gautier wrote:

            
Windows only, since 1.2.0.  It's a clone from S-PLUS, and returns the
memory in use, or the maximum ever used.  Saves watching `top' (or the
Windows task manager)!
#
Many thanks for the details... however I could find much about
the function 'memory.size' you use in your example (see below)...
is it a new function only in R-devel ?


L.

PS: In case it matters:
platform i686-pc-linux-gnu
arch     i686             
os       linux-gnu        
system   i686, linux-gnu  
status                    
major    1                
minor    5.1              
year     2002             
month    06               
day      17               
language R
On Tue, Aug 13, 2002 at 04:05:36PM +0100, ripley at stats.ox.ac.uk wrote: