[R] Call R program from C++ code
fqiu at gatech.edu
Mon Jul 30 01:15:21 CEST 2007
Thanks a lot.
>> That does not exist to the best of my knowledge.
That's sad :(
>>using the system() call -- but it is also the most tedious way as you
When using System() to call R program, do I need to call some R script
program or my R function directly?
>> A more advanced method would to use Rserve to run a 'headless' R
Here you mean Com? I don't know much about this com frame, so ....
>> In any event, you may also want to consider the RcppTemplate package
I'll read this package, hope I can find a simple way that works in my case.
From: Dirk Eddelbuettel [mailto:edd at master.debian.org] On Behalf Of Dirk
Sent: 2007Äê7ÔÂ29ÈÕ 18:17
To: Feng Qiu
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Call R program from C++ code
On Sun, Jul 29, 2007 at 04:35:51PM -0400, Feng Qiu wrote:
> I'm developing an application program using C++. From my
> code, I would call some R program I have written. I' wondering if R
> some compiler that can compile R program into executable program. I
That does not exist to the best of my knowledge.
> I might be wrong that R doesn't have complier. What I'm
> trying to do is to call R program from C++ code. Any help is highly
As you probably know, C++ can 'call' other object code that is linked
to it. As for 'calling R', the easiest way is to call an R script
using the system() call -- but it is also the most tedious way as you
to write the inout data to file, and then read the result data back
in. But it is a start, and it may be easiest to debug.
A more advanced method would to use Rserve to run a 'headless' R
service to which your C++ program can connect over the network. But
there you need to be already somewhat familiar with the underlying
C/C++ representation of R object. Rserve has simple examples.
Next, you can actually embed R inside your C++ application, but that
is more advanced.
In any event, you may also want to consider the RcppTemplate package
which has a host of examples about how to get R and C++ to work better
together (without forcing you to use C).
The 'Extending R' manual from your R installation is a good starting
point for most of this.
Hope this helps, Dirk
Three out of two people have difficulties with fractions.
More information about the R-help