[R] Error when callin g C-Code

Romain Francois romain.francois at dbmail.com
Wed Jun 16 08:50:01 CEST 2010


This is not the appropriate list for C-level questions. Please study the 
posting guide and repost on the right list.

Also, you might want to also show how you actually call this from R. Are 
you by any chance using .External instead of .Call ?

Romain

Le 15/06/10 23:20, Fabian Zäpernick a écrit :
>
> Hi
>
> when I call the function below in R, i get the error: Object 'pairlist'
> can't be converted to 'double'.
>
> #include<R.h>
> #include<Rdefines.h>
> #include<Rmath.h>
>
> SEXP CSimPoisson(SEXP lambda, SEXP tgrid, SEXP T2M, SEXP Ni, SEXP NT)
> {
> 	double sign, EVar;
> 	double *xlambda, *xtgrid, *xT2M, *xNi, *xNT, *xtau;
> 	SEXP tau;
> 	int ltgrid =0;
> 	int i = 0;
> 	int j = 0;
> 	sign = 0;
> 	EVar = 0;
> 	
> 	ltgrid  = LENGTH(tgrid);
> 	PROTECT(lambda = AS_NUMERIC(lambda));
> 	PROTECT(tgrid = AS_NUMERIC(tgrid));
> 	PROTECT(T2M = AS_NUMERIC(T2M));
> 	PROTECT(Ni = AS_NUMERIC(Ni));
> 	PROTECT(NT = AS_NUMERIC(NT));
> 	PROTECT(tau = NEW_NUMERIC(1));
> 	xlambda = NUMERIC_POINTER(lambda);
> 	xtgrid = NUMERIC_POINTER(tgrid);
> 	xT2M = NUMERIC_POINTER(T2M);
> 	xNi = NUMERIC_POINTER(Ni);
> 	xNT = NUMERIC_POINTER(NT);
> 	xtau = NUMERIC_POINTER(tau);
> 	GetRNGstate();
> 	if(xlambda[0] != 0)
> 	{
> 		while(1)
> 		{
> 			EVar = rexp(xlambda[0]);
> 			sign = sign + EVar;
> 			if (sign>  xT2M[0])
> 			{
> 				break;
> 			}
> 			xtau = Realloc(xtau, i+1, double);
> 			xtau[i] = sign;
> 			i = i+1;
> 			for(j; j<  ltgrid;j++)
> 			{
> 				if (xtgrid[j]<  sign)
> 				{
> 					xNi[j] = xNT[0];
> 				}
> 				{
> 					break;
> 				}
> 			}
> 			xNT[0] = xNT[0] + 1;
> 		}
> 		for(j;j<  ltgrid;j++)
> 		{
> 			xNi[j] = xNT[0];
> 		}
> 	}
> 	PutRNGstate();
> 	UNPROTECT(6);
> 	return tau;
> }


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/98Uf7u : Rcpp 0.8.1
|- http://bit.ly/c6YnCi : graph gallery collage
`- http://bit.ly/bZ7ltC : inline 0.3.5



More information about the R-help mailing list