Skip to content
Back to formatted view

Raw Message

Message-ID: <20785.15177.993607.181052@max.nulle.part>
Date: 2013-03-01T23:35:37Z
From: Dirk Eddelbuettel
Subject: [Rcpp-devel] reference classes in C++ :is it possible?
In-Reply-To: <CAFkVQ9M_pd+Uy_F5i7k8zxRDxGUtSM-M=1f8zdUprsmAmoz+tw@mail.gmail.com>

Hi Steven,

On 1 March 2013 at 14:34, Steven Varga wrote:
| 
| Hello
| ?
| First thanks Dirk for the quick reply and the hint; Mr.? John Chamber's
| implementation is great! gone through the documentation and followed his
| instructions. Worked well.? Only one way though -- as you pointed out.
| ?
| I was able to get the fields from the extended class; if someone could point
| into the direction how to get/execute methods of a Reference Class? then it may
| be doable??

Just making sure I understand: So you want to access part of a reference
class from C++? Wouldn't that violate the 'one way only view?

Dirk

| ?
| ?..... c++ class ......
| ??? void set_reference( SEXP xptr_){
| ??????? Rcpp::Reference ref(xptr_);
| ??????? ref.field("some_field"));?? // get the field data
| ????? ?
| // -------? this is not implemented, any hints?? --------?
| ??????? ref.method("some_method")( x, y);? // this would be nice to have
| ??? }
| ...... end .......
| ?
| setRcppClass("World",
| ??? module="yada",
| ??? fields = list( some_field = "character"),
| ??? methods = list(
| ????????? initialize = function(){
| ??????????????? some_field <<- "field value set"
| ??????????????? callSuper()??????????????? # call constructor
| ??????????????? set_reference( .self ) # pass 'this'
| ????????? }
| ???? ),saveAs="genWorld"???????
| )
| 
| On Thu, Feb 28, 2013 at 8:15 AM, Dirk Eddelbuettel <edd at debian.org> wrote:
| 
|     On 28 February 2013 at 04:44, Steven Varga wrote:
|     | I am trying to create an abstract pattern using R reference objects in
|     C++;
|     | anyone knows if this is possible/not possible? Where to look?
| 
|     I am not sure you can. The best (only ?) relevant documentation might be
|     John
|     Chamber's example of 'Rcpp Classes' (see help(setRcppClass) in R once Rcpp
|     is
|     loaded).
| 
|     And as I recall, he is pretty explicit that you can take a C++ class and
|     "extend" it for prototyping from the R side, but that you cannot access
|     those
|     extended parts from C++ as only R sees it. ?I think you are hitting a
|     similar
|     constraint here.
| 
|     It would be nice if this worked but I am not quite sure that it can.
|    
|     Dirk
| 
|     --
|     Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
| 
| 
| 
| 
| ----------------------------------------------------------------------
| _______________________________________________
| 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