[R] modifying argument of a .C call (DUP=FALSE)

From: Tamas K Papp <tpapp_at_princeton.edu>
Date: Tue 09 Aug 2005 - 03:41:02 EST


I have a huge matrix on which I need to do a simple (elementwise) transformation. Two of these matrices cannot fit in the memory, so I cannot do this in R.

I thought of writing some C code to do this and calling it using .C with DUP=FALSE. All I need is a simple for loop that replaces elements with their new value, something like

void transform(double *a, int *lengtha) {   int i;
  for (i=0; i < *lengtha; i++) {
    *(a+i) = calculatenewvaluesomehow(*(a+i))   }
}

trans <- function(a) .C("transform",as.double(a), as.integer(length(a))

is it possible to do this? The manuals say that it is dangerous, is it possible to avoid the dangers somehow?

Tamas



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Aug 09 03:44:53 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:45 EST