[R] modifying argument of a .C call (DUP=FALSE)
Tamas K Papp
tpapp at Princeton.EDU
Mon Aug 8 19:41:02 CEST 2005
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
More information about the R-help
mailing list