[R] Calling R functions from C

From: Florent Baty <florent.baty_at_unibas.ch>
Date: Sat 29 Oct 2005 - 02:01:14 EST


Dear R users,

I read on the "Introduction to the .C Interface to R" by Peng & Leeuw (http://www.biostat.jhsph.edu/~rpeng/docs/interface.pdf) that it is possible to use a few R functions (such as "dnorm") within C by including the "Rmath.h" header file in your C code: e.g.

#include <R.h>
#include <Rmath.h>
void kernel_smooth(double *x, int *n, double *xpts, int *nxpts, double *h, double *result)
{
int i, j;
double d, ksum;

for(i=0; i < *nxpts; i++) {
ksum = 0;
for(j=0; j < *n; j++) {

d = xpts[i] - x[j];
ksum += dnorm(d / *h, 0, 1, 0);
}

result[i] = ksum / ((*n) * (*h));
}
}

In the manual "Writing R extensions" there is also a list of special functions which can be called in C.

I was wondering whether there is a way to call any other R functions similarly. Is there any documented exemple available somewhere?

Thanks a lot for your help,

Florent



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 29 02:25:13 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:52 EST