Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making R function recognize C function in same package?

Tags:

c

r

I downloaded a .tgz file which contains R scripts in R/ and a single C file in src/.

An R function calls the C function in this way:

Mainfn<-function(x) {
  output <- matrix(nrow(x),ncol(x));
  output<-.C("myCfn",x=as.double(x),output=as.double(output),
             PACKAGE='mypackage')
  return(output)
}

In the C file, the function is defined this way [...] denotes a long series of computations.

#include <R.h>
#include <Rmath.h>
#include <math.h>
/*----------------------------------------------------------*/
void myCfn(double *x,double *output){
  [...]
}

When I install the package with R CMD INSTALL mypackage.tgz, Mainfun() gives an error: "myCfn" not available for .C() for package "mypackage". I wonder how I can make my function recognize this function defined in the C file?

like image 800
hatmatrix Avatar asked Apr 23 '26 08:04

hatmatrix


1 Answers

My best guess: the package needs useDynLib(<pkg_name>) in its NAMESPACE file.

like image 132
Kevin Ushey Avatar answered Apr 24 '26 22:04

Kevin Ushey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!