Hi All: I'm developing an application program using C++. From my C++ code, I would call some R program I have written. I' wondering if R provide some compiler that can compile R program into executable program. I searched R-help, there are a lot of posts talking about writing C++ code in R program, but few about calling R from C++. 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 appreciated! Best regards, Feng [[alternative HTML version deleted]]
Hi All: I'm developing an application program using C++. From my C++ code, I would call some R program I have written. I' wondering if R provide some compiler that can compile R program into executable program. I searched R-help, there are a lot of posts talking about writing C++ code in R program, but few about calling R from C++. 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 appreciated! Best regards, Feng [[alternative HTML version deleted]]
On Sun, Jul 29, 2007 at 04:35:51PM -0400, Feng Qiu wrote:> I'm developing an application program using C++. From my C++ > code, I would call some R program I have written. I' wondering if R provide > some compiler that can compile R program into executable program. I searchedThat 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 > appreciated!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.
Hi Dirk: 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 youWhen 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' RHere you mean Com? I don't know much about this com frame, so ....>> In any event, you may also want to consider the RcppTemplate packageI'll read this package, hope I can find a simple way that works in my case. Thanks again! Best, Feng -----Original Message----- From: Dirk Eddelbuettel [mailto:edd at master.debian.org] On Behalf Of Dirk Eddelbuettel 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 myC++> code, I would call some R program I have written. I' wondering if Rprovide> some compiler that can compile R program into executable program. Isearched 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 > appreciated!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.
"Writing R Extensions" manual contains chapters dedicated to parsing and evaluating of the R extensions from C. Also, I vaguely remember I've seen something like "Embedding R" somewhere in manuals. R can be compiled as a shared library object, that you can dynamically load from your application and use its functions. R doesn't have a compiler, it's the interpreted language. However, it can parse a character string representing an expresstion and transform it into the internal form, ready for evaluation. Feng Qiu wrote:> > Hi All: > > I'm developing an application program using C++. From my > C++ > code, I would call some R program I have written. I' wondering if R > provide > some compiler that can compile R program into executable program. I > searched > R-help, there are a lot of posts talking about writing C++ code in R > program, but few about calling R from C++. > > 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 > appreciated! >-- View this message in context: http://www.nabble.com/Call-R-program-from-C%2B%2B-code-tf4167083.html#a11860280 Sent from the R help mailing list archive at Nabble.com.