Le 19/02/13 17:21, Hadley Wickham a écrit :
Hi all,

I'd like to have a simple C++ object that I can work with in either
C++ or R.  I can create the class, and expose it to R with modules
(https://gist.github.com/hadley/4987110), but I don't know how to
write the SEXP constructor or SEXP() operator to make it easy to move
it back and worth between C++ and R. I presume I just have to grab and
cast an external pointer, but I don't know the structure of the R
object that the module creates. Could anyone point me in the right
direction?

Thanks!

Hadley

Unfortunately, at the moment modules and attributes don't play together. The attributes feature used to be built on top of modules, but this caused issues on windows.

One thing we could perhaps negociate with JJ is recognition of the export attribute on module. Something like :

// [[Rcpp::export]]
RCPP_MODULE(SimpleModule) {
  class_<Simple>( "Simple")
        .constructor<double>()
        .const_method("times", &Simple::times)
  ;
}

or perhaps even just recognizing the RCPP_MODULE declaration.

Once we have that, you won't need the SEXP constructor or the SEXP conversion operator, and you would only need that before your class declaration:

RCPP_EXPOSED_CLASS(Simple)

So that as and wrap are taken care of.

Romain

--
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/14LJhmm : bibtex 0.3-5
`- http://bit.ly/RE6sYH  : OOP with Rcpp modules

_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to