Re: [R] .C help

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

See 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 

    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 Tuszynski, PhD.                           o / \ 
 Science Applications International Corporation  <\__,|  
 (703) 676-4192                                   ">  \                     `   \ 

-----Original Message-----
[] On Behalf Of Elizabeth Lawson Sent: Friday, September 30, 2005 2:46 PM To:
Subject: [R] .C help


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)






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?  


Elizabeth Lawson


 Click here to donate to the Hurricane Katrina relief effort.

        [[alternative HTML version deleted]] mailing list PLEASE do read the posting guide! mailing list PLEASE do read the posting guide! 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