[R] using fmod in C code to be loaded into R

Faheem Mitha faheem at email.unc.edu
Tue Feb 27 05:57:10 CET 2001

Dear People,

I wrote the following bit of C code and (along with other bits) called it
mycode.c, and compiled the file into a shared library to load into R,
using R CMD SHLIB mycode.c. This was Ok, but when I tried to load this
into R using dyn.load("mycode.so") I got the error

> dyn.load("mycode.so")
Error in dyn.load(x, as.logical(local), as.logical(now)) : 
	unable to load shared library "/home/faheem/research/mycode.so":
  /home/faheem/research/mycode.so: undefined symbol: Rf_fmod

"Writing R extension" says this function is available as an entry point.
I have only a vague undertstanding of entry points, but I understand this
to mean that if I am going to load the compiled code into R to be called
from R, then I can stick such a function in my code, and provided I have
the header Rmath.h included, everything will be Ok.

This works with rnorm, for example. What am I doing wrong here?

                     Sincerely, Faheem Mitha.


#include <R.h>
#include <Rinternals.h>
#include <Rmath.h>

 double absdiff(double *array, Sint *narray, Sint *lag, double
 int i;
  for(i=0; i < *narray - *lag; i++)
    diffarray[i] = fmod(array[i + *lag] - array[i],1);

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