[R] Foreign code problem

Rolf Wester rolf.wester at ilt.fraunhofer.de
Wed Oct 6 13:00:44 CEST 2004


I wanted to test the odesolve package and tried to use compiled C-code.
But when I do:

erg <- lsoda(y, times, "mond", parms, rtol, atol, tcrit=NULL, jacfunc=NULL,
               verbose=FALSE, dllname="mond", hmin=0, hmax=Inf)

I get the error message:

Error in lsoda(y, times, "mond", parms, rtol, atol, tcrit = NULL,             
               jacfunc = NULL,  : 
    Unable to find mond in mond

The C code is:

#include <math.h>

void mond(long int *neq, double *t, double *y, double *ydot)
	double a = sqrt(y[2]*y[2] + y[4]*y[4]);
	a = -1.0/(a*a*a);
	ydot[0] = a*y[1];
	ydot[1] = y[0]; 
	ydot[2] = a*y[3];
	ydot[3] = y[2];

and mond.so is build by:

gcc -O3 -shared mond.c -lm -o mond.so

I have set LD_LIBRARY_PATH to the correct directory and also tried to use the full path of mond.so in the call to lsoda but got the same error message. I would be very appreciative for help in order to understand how compiled code can be used from within R.

Besides this I have a further question. Am I right that every function argument is copyied when calling a function, even if the argument is a 
huge matrix? Wouldn't that be very inefficient?

Thank you very much in advance


Rolf Wester

P.S.: I'm new to R and find it is a great tool and programming environment.

More information about the R-help mailing list