[R] the use of the .C function

Bernardo Lagos Alvarez bla at udec.cl
Sat Oct 13 19:26:38 CEST 2007


Hi all,

here others doubts, when load and running the function

void gdot(double *x,double *y,int *n,double *output){
int i;
*output=0;
for (i=0;i<*n;i++){
*output+=x[i]*y[i];
}
}


as following

/examplesC$ R CMD SHLIB xby.c
gcc -std=gnu99 -I/usr/share/R/include -I/usr/share/R/include      -fpic  -g -O2 -c xby.c
-o xby.o
gcc -std=gnu99 -shared  -o xby.so xby.o   -L/usr/lib/R/lib -lR

/examplesC$ R
>x<-c(1,4,6,2)
>y<-c(3,2.4,1,9)
> dyn.load("xby.so")
>product<-.C("gdot",myx=as.double(x),myy=as.double(y),myn=as.integer(NROW(x)),myoutput=numeric())

 *** caught segfault ***
address (nil), cause 'memory not mapped'

Traceback:
 1: .C("gdot", myx = as.double(x), myy = as.double(y), myn = as.integer(NROW(x)),    
myoutput = numeric())

Possible actions:
1: abort (with core dump)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection:
Selection:
Selection:


Can anybody answerme that happening with this Traceback?


Thanking you in advance,
Bernardo Lagos A.



More information about the R-help mailing list