Re: [Rcpp-devel] c++ class as argument in rcpp function (using modules)

2011-12-23 Thread ian . fellows
t;RcppArmadillo") : installation of package 'RcppArmadillo' had non-zero exit status -- Message: 2 Date: Fri, 23 Dec 2011 18:16:36 -0500 From: Yasir Suhail Subject: Re: [Rcpp-devel] c++ class as argument in rcpp function (using modules)

Re: [Rcpp-devel] c++ class as argument in rcpp function (using modules)

2011-12-23 Thread Dirk Eddelbuettel
On 23 December 2011 at 18:16, Yasir Suhail wrote: | Hi, | | I think I have figured out why we were getting the error. When we call the | function from R, the type of the instance passed is S4SXP, rather than | EXTPTRSXP, which is what XPtr(SEXP) expects. That's possible. | We can, however, u

Re: [Rcpp-devel] c++ class as argument in rcpp function (using modules)

2011-12-23 Thread Yasir Suhail
Hi, I think I have figured out why we were getting the error. When we call the function from R, the type of the instance passed is S4SXP, rather than EXTPTRSXP, which is what XPtr(SEXP) expects. We can, however, use the Rcpp::S4(SEXP) constructor to get an S4 object. Are the user defined C++ class

Re: [Rcpp-devel] c++ class as argument in rcpp function (using modules)

2011-12-22 Thread Yasir Suhail
Hi, Dirk, thanks for uploading the next version, because it does sort of help here. The error now with Rcpp 0.9.8 is "expecting an external pointer" from XPtr on the following very toy example. It has something to do with the type of SEXP in the constructor, but I am not very familiar with the Rcp

Re: [Rcpp-devel] c++ class as argument in rcpp function (using modules)

2011-12-21 Thread Yasir Suhail
Hi, Other than the approaches mentioned, I can also specialize an as(SEXP) as template <> World as(SEXP x) { Rcpp::XPtr ptr(x); return World(ptr->greet()); } However, this also gives segfault at runtime when addMsg is called. The final code, with alternative implementations commen

Re: [Rcpp-devel] c++ class as argument in rcpp function (using modules)

2011-12-21 Thread Yasir Suhail
Thanks Darren, Douglas, Richard, and Dirk! I can compile with the following definitions: World(SEXP x) { Rcpp::XPtr ptr(x); msg = ptr->msg; } and World(SEXPREC* &w2) { msg = ((World*)w2)->msg; } With the SEXPREC* & definition, I get a runtime segfault: > a <- new(World,"sdf") > b <- new(World,

Re: [Rcpp-devel] c++ class as argument in rcpp function (using modules)

2011-12-21 Thread Darren Cook
> void addMsg(World& w2) { > msg = msg + w2.msg; > } BTW, this could be (and should be) void addMsg(const World& w2) { ...} > error: no matching function for call to ‘World::World(SEXPREC*&)’ How about something like: World(SEXPREC* &w2){ msg= ((World*)w2)->msg; } Darren --

Re: [Rcpp-devel] c++ class as argument in rcpp function (using modules)

2011-12-21 Thread Dirk Eddelbuettel
On 21 December 2011 at 16:29, Douglas Bates wrote: | On Wed, Dec 21, 2011 at 3:55 PM, Yasir Suhail wrote: | > Hi | > | > I looked up the previous thread "Creating pointers to objects and wrapping | > them" | > from http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2011-April/002170.html, |

Re: [Rcpp-devel] c++ class as argument in rcpp function (using modules)

2011-12-21 Thread Douglas Bates
On Wed, Dec 21, 2011 at 3:55 PM, Yasir Suhail wrote: > Hi > > I looked up the previous thread "Creating pointers to objects and wrapping > them" > from http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2011-April/002170.html, > and it seems that providing a specialization of the wrap<>() fun

Re: [Rcpp-devel] c++ class as argument in rcpp function (using modules)

2011-12-21 Thread Tama Ma
Dear all, This is something I desire for a long time, but I do not have currently the time to do that. Let me summarize my desire: 1) Copy constructor 2) Rcpp module objects being wrapped so that they could become arguments in C++ functi

Re: [Rcpp-devel] c++ class as argument in rcpp function (using modules)

2011-12-21 Thread Richard Downe
A slightly hackish, if effective, workaround I've used in this instance is to have "as<>()" convert a string argument to a class return value, thereby avoiding the metaphysics of creating a c++ class in R. template <> fusionProject::TCFAFunctor *as( SEXP rs ) { using fusionProject::

Re: [Rcpp-devel] c++ class as argument in rcpp function (using modules)

2011-12-21 Thread Yasir Suhail
Hi I looked up the previous thread "Creating pointers to objects and wrapping them" from http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2011-April/002170.html, and it seems that providing a specialization of the wrap<>() function can help us return classes. Perhaps similarly, one could pr

Re: [Rcpp-devel] c++ class as argument in rcpp function (using modules)

2011-12-21 Thread romain
Iirc, this is not implemented yet. There is a chance we might add this feature in the future. Cheers, Romain Le 21 déc. 2011 à 10:59, Yasir Suhail a écrit : > I need to pass a class as an argument in a function I am exposing to R. From > the skeleton package module, let us say that I ha