[Rd] embedding R in c++ (Qt) application

Dirk Eddelbuettel edd at debian.org
Wed Jun 18 14:46:13 CEST 2008


Peter,

On 18 June 2008 at 14:13, Peter.Peyk at unibas.ch wrote:
| Hi R-Developers,
| 
| I'm working on running statistical analyses with embedded R from a  
| Qt-GUI-application (C++).
| 
| I've been able to link with R libraries, but I'm having a hard time to  
| understand the C-coding examples. I'm a C++, not a C programmer (never  
| used malloc before), and many of the R-specific  
| functions/keywords/macros (for instance (UN)PROTECT, SETCAR, all the  
| data types (SEXP, CHARSXP etc..) ) don't mean anything to me. The  
| section on the SEXP type in the R-internals doc didn't tell me much.  
| How can I create such objects containing my data? how can I extract  
| numbers or strings from SEXPs?

Have a look at RCpp at http://r-forge.r-project.org. While initially written
for accessing C++ from R, it works perfectly well the other way too.  Thanks
to a number of (templated) classes, it abstracts away a lot of the underlying
C representation.

I also use for embedded R inside of C++. 

[...]

| My goal is to prepare some data for R to run an ANOVA on, run it, and  
| retrieve the results to display them on the GUI. Can you suggest me a  
| helpfiles/documentations to read for this?

That should work just fine. One of my apps at work gathers simulation data in
STL vectors of vectors, passes that to an R matrix via one RCpp invocation. I
then assign that object to an R object in the embedded R instances, and let R
run analysis on it.  Much nicer / easier than going the old route of export
to csv, calling R, reimportting, ....

Hth, Dirk

-- 
Three out of two people have difficulties with fractions.



More information about the R-devel mailing list