[R] Error when callin g C-Code

From: Fabian Zšpernick <fab.zaep_at_web.de>
Date: Tue, 15 Jun 2010 23:20:58 +0200


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;

}

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 15 Jun 2010 - 22:56:04 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 16 Jun 2010 - 07:10:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive