[Rcpp-devel] modules feature added (rev 3814)

Romain Francois romain at r-enthusiasts.com
Tue Oct 23 15:55:01 CEST 2012


I've added the possibility for exposed classes to expose a method that 
returns a pointer of the class. That is not easy to explain in a 
sentence, here is an example code:

class Foo{
             Foo( double x_, double y_) : x(x_), y(y_){}

             Foo* clone(){
                 return new Foo( x, y) ;

             double x, y ;

     } ;

The "clone" method return a Foo*, and so previously it could not be 
exposed to R with modules.

Now, with commit 3814, we can write:

class_<Foo>("Foo" )
             .method( "clone", &Foo::clone )

             .field( "x", &Foo::x )
             .field( "y", &Foo::y )


And on the R side:

 > x <- new( Foo, 2.4, 3.5 )
 > y <- x$clone()

Thos are not the same objects (not the same internal pointer)
 > x
C++ object <0x1006e1e20> of class 'Foo' <0x1006ccb60>
 > y
C++ object <0x10330cc00> of class 'Foo' <0x1006ccb60>


Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
R Graph Gallery: http://gallery.r-enthusiasts.com
blog:            http://romainfrancois.blog.free.fr
|- http://bit.ly/xbKv0R : Crawling facebook with R
|- http://bit.ly/v3WB8S : ... And now for solution 17, still using Rcpp
`- http://bit.ly/uaQDGr : int64: 64 bit integer vectors for R

More information about the Rcpp-devel mailing list