[Rcpp-devel] Invoking class methods via XPtr<> objects in R

Dirk Eddelbuettel edd at debian.org
Wed Mar 13 22:56:07 CET 2013


On 13 March 2013 at 10:15, Suresh Easwar wrote:
| How does one invoke class methods via XPtr<T> objects in R? I get this error: Error in aptr$f : object of type 'externalptr' is not subsettable:

I don't understand what you are trying to do below, and do not have time to
understand and debug it for you.

Your example is also complicated as you mix XPtr and Modules.  Maybe you will
have more success walking in smaller steps --- and a working example of XPtr
via Rcpp is in the RcppDE package where I use XPtr to pass external
(user-given) C interface functions around to the optimiser.

Dirk

|  
| cpp file:
| #include <Rcpp.h>
| struct A {
| void f() {}
| };
| typedef Rcpp::XPtr<A> APtr;
| APtr getAPtr()
| {
| return APtr(new A);
| }
| struct B {
| B(APtr) { }
| };
| RCPP_MODULE(mytest)
| {
|                 Rcpp::function("get_aptr", &getAPtr);
|                 Rcpp::class_<A>("A")
|                                 .constructor()
|                                 .method("f", &A::f)
|                 ;
|                 Rcpp::class_<B>("B")
|                                 .constructor<APtr>()
|                 ;
| }
|  
| R session:
| R version 2.15.3 (2013-03-01) -- "Security Blanket"
| Copyright (C) 2013 The R Foundation for Statistical Computing
| ISBN 3-900051-07-0
| Platform: x86_64-unknown-linux-gnu (64-bit)
| > library(mytest)
| Loading required package: Rcpp
| > a <- new(A)
| > aptr <- get_aptr()
| > b <- new(B, aptr)
| > a$f()
| > aptr$f()       <- not sure how to invoke f() via aptr
| Error in aptr$f : object of type 'externalptr' is not subsettable
| > 
|  
| Thanks
|  
| Suresh
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  


More information about the Rcpp-devel mailing list