[R] R function use in C returning a list

Vumani Dlamini dvumani at hotmail.com
Thu Feb 23 18:28:34 CET 2006


Dear R users,
Is it possible to use an R function accepting several arguments and 
returning a list in C code. I notice that in all examples only one variable 
is returned.
Here is the C part I feel is giving the problems,

	SEXP R_fcall, ans;
	PROTECT(R_fcall = lang2(likelihood, R_NilValue));
	++nProtected;
	defineVar(install("PAR"), PAR, env);
	defineVar(install("DATA"), oldData, env);
	defineVar(install("N"), N, env);
	PROTECT(ans =  eval(R_fcall, env));

oldData is a matrix which i set using

	SEXP dim;
	PROTECT(dim = NEW_INTEGER(2));
	++nProtected;
	INTEGER_DATA(dim)[0] = n;
	INTEGER_DATA(dim)[1] = 2;
	setAttrib(oldData, R_DimSymbol, dim);

if i return both function and data they are ok, but its evaluating the 
function and returning the list or even a single number which is a problem.
Thanks again, Vumani




More information about the R-help mailing list