Skip to content
Prev 75185 / 398502 Next

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

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