Message-ID: <20050808174058.GA31325@tpapp.student.princeton.edu>
Date: 2005-08-08T17:41:02Z
From: Tamas K Papp
Subject: 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