[Rd] modifying large R objects in place

From: Petr Savicky <savicky_at_cs.cas.cz>
Date: Wed, 26 Sep 2007 11:29:24 +0200

I have a C function, which performs a transformation of a large integer matrix. The matrix may be of size 1.6GB, so I can have only one copy in RAM and have to modify it in place. This is possible using .Call and works fine. For debugging, I need two copies of a smaller matrix and modify only one of them. This may also be done, for example, by   A <- some integer matrix
  B <- A + as.integer(0)
  .Call("transform", A)
Then, B is still the original and A is the transformed one. Up to now, I do not have any real problem with this, but there are things, which could help me. Namely the following ones:

  1. Is there a general way to duplicate an R object on the level of R language? I would use it instead of B <- A + as.integer(0) Looking for the keywords "duplicate" and "copy" in help pages and R-exts did not find what I need.
  2. Is there a way how a C function can verify that its argument does not share data with other objects? I included a test of NAMED(A) in my C function, but I do not know, whether it may be used for the purpose which I need. I did not find a way how to generate an R object with NAMED equal 0. Is this possible on the level of R language? If yes, I will require that the argument passed to my function is generated in this way and the function will refuse to modify it if it is not so. The documentation suggests to call "duplicate", if the data are shared, but I cannot afford this due to memory. So, I can only stop if NAMED is not 0.

I appreciate, if anybody could give me advice on the above things.

Petr Savicky.

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 26 Sep 2007 - 09:38:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 26 Sep 2007 - 18:41:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.