Re: [R] .C help

From: Tuszynski, Jaroslaw W. <JAROSLAW.W.TUSZYNSKI_at_saic.com>
Date: Sat 01 Oct 2005 - 06:24:11 EST


See http://www.stats.uwo.ca/faculty/murdoch/software/compilingDLLs/ and "R Installation and Administration" manual for details that will have to be followed very precisely.

My own 2 cents below should be taken as fuzzy recollections, compared to detailed directions in 2 sources above. I do not know if they are the easiest or even correct, but they work.

There are 2 ways to compile that I tried (both use MinGW compiler): - compile C into dll. Copy dll to the same directory as R functions.

    I was compiling on WIN XT machine by double clicking on "any-name.bat" text file containing:

         cl /MT /Ox /D "WIN32"  /c runfunc.c
         link /dll /EXPORT:runquantile /EXPORT:runmean /EXPORT:runmad
/out:runfunc.dll *.obj 
         pause

    My code was in "runfunc.c". C Functions I was planning on calling were:
"runquantile" "runmean" "runmad". DLL name was "runfunc.dll"

Both of those approaches (I think) required R beeing installed in a path with no spaces (for example R can not be installed in default spot
"c:\Program Files\R" since "program files" have space between two words.
Also I remember having a lot of trouble ordering directories on my PATH (envirinmental variable - see "my computer/properties/advanced/Environment Variables").

 Jarek

====================================================\==== 
 Jarek Tuszynski, PhD.                           o / \ 
 Science Applications International Corporation  <\__,|  
 (703) 676-4192                                   ">  \ 
 Jaroslaw.W.Tuszynski@saic.com                     `   \ 



-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch
[mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Elizabeth Lawson Sent: Friday, September 30, 2005 2:46 PM To: r-help@stat.math.ethz.ch
Subject: [R] .C help

Hi,  

I am hoping some one can help me. I am learning to use C and would like to learn how to call c code in R. I have look at Writing R Extensions    

and I tried to copy the example on page 38  

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    

and I got the error "C" function name not in load table.  

Do I need to compile the C code first?

Do I need a c copmiler at all?  

Any suggestions for a begginner?  

Thanks,  

Elizabeth Lawson

I                 


 Click here to donate to the Hurricane Katrina relief effort.

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Oct 01 06:28:49 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:07:14 EST