This error means that an implicit type casting takes place when returning the result at the end of the function. In this case, the function was defined as returning an int(eger) while the returned variable wasn’t one. The fix was obviously to correct the definition of the function (or, if appropriate, to cast the returned variable into an int before returning it).
Personally, I encountered that error while trying to make a simple hello world R function, as I’m not really good at playing with R’s custom types: I defined my function to return an int, while it was in fact returning a “SEXP” (whatever that is… :D).
Bonus: here’s the fixed code (I’ll try to publish the whole R Hello World package when I’m done with it):
#include <R.h>
#include <Rinternals.h>SEXP helloWorldC(SEXP n, SEXP m)
{
double *nn = REAL(n), *mm = REAL(m);
double *res = NULL;
SEXP result;/* allocate and initialize result to zero. */
PROTECT(result = allocVector(REALSXP, 1));
res = REAL(result);
*res = 0;*res = *nn * *mm;
if(*res==42) *res=1;
else *res=0;UNPROTECT(1);
return result;
}
Bonus 2: if you want to read more about type casting in C++ (yes, I know the code above is in C ;)).
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.