[R] correct C function usage

Ido M. Tamir tamir at imp.univie.ac.at
Tue Dec 13 20:31:54 CET 2005


Hello,
I am not sure if I am interfacing with C correctly and _safely_ 
or if there is a better way esp. with regards to terminating 
the "returned" array.

I am trying to fill an int array with values whose actual size
is determined in the C function and is always maximally as large
as length(values).

I also don't understand the purpose of $ab in the example:
conv <- function(a, b)
       .C("convolve",
      -snip-
          ab = double(length(a) + length(b) - 1))$ab




void testFill(int *values, int *newvalues, int* endposition ){
         newvalues[0] = 1;
         newvalues[1] = 2;
         *endposition = 2;
}

dyn.load("../testFill.so")

testTestFill <- function(){
  tempfilled <- testFillC( c(30:40))
  realfilled <- tempfilled$newvalues[1:tempfilled$endposition]
  return(realfilled)
}

testFillC <- function(a){
  .C("testFill", as.integer(a), newvalues=integer(length(a)), 
endposition=integer(1))
}


Thank you very much in advance
Ido Tamir




More information about the R-help mailing list