[R] how to call R function from my C++ program

Yan Yu yanyu at cs.ucla.edu
Sun May 4 02:25:29 CEST 2003


Hi,
I read the manual, it seems that i have the following two choices:
1) use "eval(R_fcall, rho)" in a C function.

They use an example called lapply2

in C program, it has:
SEXP  lapply2(SEXP list, SEXP fn, SEXP rho)
{
.....
PROTECT( R_fcall = lang2(fn, R_nilValue) );
eval(R_fcall, rho)
......
}

but i am a little confused here, it seems like the C function "lapply2()"
is supposed to be called from R, not to be run standalone??
My Q is: if I use this approach, Can I run a standalone C program in which
I call a R function using eval()?

2) R have some API entry points for C code.
in section 5.12, it says "it is possible to build Mathlib, can be built in
directory "src/namth/standalone", and the instructions are supposed in
"README" in the same directory.
I am wondering using the same procedure, can I build API entry points for
other R functions I want to use?

I have another Q, there is no "src" subdirectory in my R directory.
i use i386 rpm to install R in my redhat..
i think the version i have now is R-1.6.1-1.i386.rpm..
Any idea where can i find this src subdirectory?

thanks a lot,
yan

On Fri, 2 May 2003, Roger Peng wrote:

> It is possible to call R functions from a C++ program.  I suggest reading
> the manual "Writing R Extensions" available under the manuals section of
> CRAN.
>
> -roger
> _______________________________
> UCLA Department of Statistics
> http://www.stat.ucla.edu/~rpeng
>
> On Fri, 2 May 2003, Yan Yu wrote:
>
> > Hello, there,
> >   Is it possible to call R function from my C++ program?
> > If yes, How?  what function I should look up for that purpose?
> > If someone could provide some pointe, that would be very helpful..
> >
> > THe reason I want to do that is that for my analysis, I need to do part of
> > the work in Matlab (I find the matrix operation in Matlab is very
> > convenient), and part of work in R, and I would like to connect
> > them automate the whole process using my C++ program..
> >
> > THanks a lot in advance!
> > have a nice weekend,
> > yan
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> >
>



More information about the R-help mailing list