[R] C dll compilation + S Poetry example

Duncan Murdoch murdoch at stats.uwo.ca
Tue Jan 6 11:45:02 CET 2009


On 05/01/2009 11:26 PM, Pedro Mardones wrote:
> 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.

is.loaded is looking for a symbol name, not a DLL name:  you want 
is.loaded("quad_form_Sp").

Duncan Murdoch

> 
> Can anyone point me out to where could be the problem with the
> quadratic form example?
> 
> Thanks
> 
> PM
> 
> ______________________________________________
> 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.




More information about the R-help mailing list