[R] help in R calling C function

Lei Liu liulei at l.imap.itd.umich.edu
Sun Jun 27 09:18:43 CEST 2004

Hi there,

I want to call a C function in R. I have some experience on it, but this 
time I need to call another C function in the "main" C function. As a 
simple example, I use the following C code:

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>

void main(double *alpha)
	double test();
	double beta;
	beta= *alpha *2 + test(*alpha);

double test(double *alpha)
	double value;
	value = *alpha *3;

I used "gcc -c main.c" and "Rcmd SHLIB main.o" and I got the main.dll file. 
In R I use the following code to call the C function "main":

dyn.load("c:/Program Files/R/rw1060/bin/main.dll")
b=.C('main', as.double(a))

But the R system crashed. I know I can only define the function type in C 
as "void" to be called by R. But what if I want to call another C function 
in the "main" C function? Thank you for your help!


Lei Liu

More information about the R-help mailing list