[R] correct C function usage

From: Ido M. Tamir <tamir_at_imp.univie.ac.at>
Date: Wed 14 Dec 2005 - 06:31:54 EST


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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Dec 14 08:25:29 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:36 EST