Dear all, I'm studing how to include .c code in my .r functions . In the R-exts.pdf manual I have found the following code. At one point the author write "called from R by"... How can I load a .c file on R? ( I am using a xp windows as so.) Thank you ale void convolve(double *a, int *na, double *b, int *nb, double *ab) { int i, j, nab = *na + *nb - 1; for(i = 0; i < nab; i++) ab[i] = 0.0; for(i = 0; i < *na; i++) for(j = 0; j < *nb; j++) ab[i + j] += a[i] * b[j]; } #called from R by ?????????????????????? conv <- function(a, b) .C("convolve", as.double(a), as.integer(length(a)), as.double(b), as.integer(length(b)), ab = double(length(a) + length(b) - 1))$ab
On Wed, 7 Apr 2004 15:55:38 +0200, "Alessandro Soranzo" <soranzo at psico.univ.trieste.it> wrote :>Dear all, >I'm studing how to include .c code in my .r functions . In the R-exts.pdf >manual I have found the following code. At one point the author write >"called from R by"... >How can I load a .c file on R? ( I am using a xp windows as so.)You need to compile it into a DLL. How to do that depends on your compiler. Instructions for the recommended compiler (MinGW's gcc) are in the readme.packages file (which should have been installed in the R home directory). Instructions for some other compilers are on my web page, at <http://www.stats.uwo.ca/faculty/murdoch/software/compilingDLLs/>.>} >#called from R by ?????????????????????? >conv <- function(a, b) >.C("convolve", >as.double(a), >as.integer(length(a)), >as.double(b), >as.integer(length(b)), >ab = double(length(a) + length(b) - 1))$abThis will look for a function named "convolve", in one of the loaded DLLs. It's safer (and R CMD CHECK now warns you about this) to specify the package where "convolve" lives; then the search will look in the DLL for that package. See the help for .C for the syntax. Duncan Murdoch