[R] C dll compilation + S Poetry example

Pedro Mardones mardones.p at gmail.com
Tue Jan 6 05:26:43 CET 2009


Dear all;

Working with the following code extracted from the document S Poetry
by Patrick Burns (from CRAN), I haven't been able to load the
resulting  dll into R. The code is basically the calculation of the
quadratic form x'Qx:

static double quad_form(double *Q, double *x, long n)
{
	long i, j, ij;
	double ans = 0.0;

	for(i=0; i < n; i++) {
		for(j=0, ij = i * n; j < n; j++, ij++) {
			ans = ans + x[i] * Q[ij] * x[j];
		}
	}
	return(ans);
}


void quad_form_Sp(double *Q, double *x, long *xdim, double *ans)
{
	long i, ii, n;
	double quad_form(double*, double*, long);

	n = xdim[0];

	for(i=0, ii=0; i < xdim[1]; i++, ii += n) {
		ans[i] = quad_form(Q, x + ii, n);
	}
}

The dll was compiled (in Win XP, R-2.8.1) using the command: rcmd
SHLIB qform.c. Then in R I typed: > dyn.load("qform.dll") and some
other variants but > is.loaded("qform") it always returns FALSE. Now I
followed the same steps using the convolution example provided by
Venables (S Programming book) and it works fine.

Can anyone point me out to where could be the problem with the
quadratic form example?

Thanks

PM




More information about the R-help mailing list