[R] dyn.load and c-function

Jeff D. Hamann jeff_hamann at hamanndonald.com
Tue Oct 8 08:11:45 CEST 2002


I've got a c function in a dll and have been able to call it from R. The
function is :

void __stdcall testfunc2(
  unsigned long *a,
  double        *b,
  unsigned long *c,
  double        *result )
{
    *result = 0;

    *result = (*a) * (*b) * (*c);
}

and the R code to call the function is as follows:

dyn.load("c:/openfvs/biometrics/debug/biometrics.dll" )
tf2 <- function( a, b, c, d )
  .C("testfunc2",
     as.integer(a),
     as.double(b),
     as.integer(c),
     as.double(d) )

I'm having a little trouble getting the value out of the R function. I would
like to be able to call the R funcion as :

val <- tf2( a, b, c )

when I'e tried to call the function as:

tf2 <- function( a, b, c )
  .C("testfunc2",
     as.integer(a),
     as.double(b),
     as.integer(c),
     as.double(d) )[[4]]

I get an "Object d not found" error...

how would I write the R part so that I can call my function the way I want
to?

Thanks,
jeff.





Jeff D. Hamann
Hamann, Donald & Associates, Inc.
PO Box 1421
Corvallis, Oregon USA 97339-1421
Bus. 541-753-7333
Cell. 541-740-5988
jeff_hamann at hamanndonald.com
www.hamanndonald.com


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list