[R] .C help
Tuszynski, Jaroslaw W.
JAROSLAW.W.TUSZYNSKI at saic.com
Fri Sep 30 22:24:11 CEST 2005
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
My code was in "runfunc.c". C Functions I was planning on calling were:
"runquantile" "runmean" "runmad". DLL name was "runfunc.dll"
- follow the steps as if you were building a package (even if you are not
planing on releasing it). This way was much easier, but only after I
installed many other tools needed for package instalation/compilation. After
everything was correctly set up the actual package compilation is done by
double-clicking on "C:\programs\R\rw2011\src\gnuwin32\install_caTools.bat"
text file containing:
RCMD install C:/programs/R/rw2011/src/library/caTools
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
Jarek Tuszynski, PhD. o / \
Science Applications International Corporation <\__,|
(703) 676-4192 "> \
Jaroslaw.W.Tuszynski at saic.com ` \
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Elizabeth Lawson
Sent: Friday, September 30, 2005 2:46 PM
To: r-help at stat.math.ethz.ch
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?
Click here to donate to the Hurricane Katrina relief effort.
[[alternative HTML version deleted]]
R-help at stat.math.ethz.ch mailing list
PLEASE do read the posting guide!
More information about the R-help