[Rd] How difficult is it to wrap a large C++ library with R?

Bo Peng ben.bob at gmail.com
Mon Jul 4 22:37:34 CEST 2005


> > * Wrap C++ class hierarchy. Virtual functions need to be supported.
> > (SWIG can generate Python shadow classes that behave almost exactly
> > like the underlying C++ classes)
> 
> This is hard to do in R, because the R object model is quite different
> from that of C++ (whereas Python's is more similar).

I guess I will have to learn R OOP in detail first. It would be
terrible if I will have to re-write every C++ class in R (and without
inheritance)!

> > * Direct access to C++ data structure. For example, an object may keep
> > a C array internally. I will need a method (maybe wrap this data into
> > a R object) to read/write this array directly.
> 
> That's not too hard provided you use C++ code to do the actual access.
> That is, you write an R function that calls C++ code to do the work.
> It's a lot harder if you want to keep it all in R, because it doesn't
> understand C++ type definitions, alignment conventions, etc.

So this has to be done through functions. In Python, I can create an
object to wrap C array that can be accessed just like regular list. I
guess it would be difficult to create a new data type in R.

Anyway, where can I find the most complete information about
implementation of R/OOP at C/C++ level? (Or should I write classes in
R and call C++ functions for every member function?) I have not read
http://cran.r-project.org/doc/manuals/R-exts.pdf in detail but my
impression is that almost everything is done at a function (not
object) level using .C().

Thanks.
Bo



More information about the R-devel mailing list