[Rd] .C and .Call: convolve example not working
Lars Wißler
jahftw at googlemail.com
Thu Aug 11 15:06:07 CEST 2011
Dear R users,
I want to call C code via the .C or .Call interface. This works fine
with integer values but using doubles the array received in C will be
set to zeros.
I have tried the convolve examples (Writing R extensions, chapter 5.2)
and still the resulting array consists of zeros.
My code (shortened for my purposes. Original did not work either):
------------------------------------------------------------
convolve.r
a=array(1, c(4))
b=array(3, c(4))
print(a)
print(b)
.C("convolve",
as.double(a),
as.double(b))
----------------------------------------------------------------
convolve.c
void convolve(double* a, double* b){
int i;
for(i=0;i<4;i++) Rprintf("a: %d", a[i]);
for(i=0;i<4;i++) Rprintf("b: %d", b[i]);
}
--------------------------------------------------------------
ouput:
[1] "starting C code..."
[1] 1 1 1 1
[1] 3 3 3 3
a: 30467528
a: 0
a: 0
a: 0
b: 0
b: 0
b: 0
b: 0
Any suggestions as to why this is happening and what I am doing wrong
would be much appreciated. I have tried .Call with conversion SEXP to
double with REAL(a)/REAL(b) with the same results (the entry first
entry of a has a different number, but is huge as well). I am quite
astonished with the results I am getting.
Thanks and regards,
Lars Wissler
More information about the R-devel
mailing list