[R] loading c code in windows ambient

Duncan Murdoch dmurdoch at pair.com
Wed Apr 7 19:21:17 CEST 2004


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))$ab

This 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




More information about the R-help mailing list