[R] correct C function usage

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

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)
          ab = double(length(a) + length(b) - 1))$ab

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


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

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

Thank you very much in advance
Ido Tamir

More information about the R-help mailing list