Skip to content
Prev 1262 / 10988 Next

[Rcpp-devel] Rcpp and reference classes in R-2.12.0 and later

On Mon, Nov 1, 2010 at 3:28 PM, Douglas Bates <bates at stat.wisc.edu> wrote:

            
The last example I sent was for accessor functions (auto-generation
of getX() and setX()). To use accessor fields you can do something
like:

clgen <- setRefClass("Myclass",
    fields = list(extptr = externalptr,
      xyz = function(arg=nil) {
          .Call('accessorXyz',extptr, arg)
      })

Here extptr will have to be set in an initialize method, and
the .Call will return xyz (a field in the C++ structure
pointed to by extptr) when arg is nil, otherwise the
supplied arg will be assigned to this field.

Romain has partially wrapped this process in Module,
where you can get a similar effect with:

clgen <- Module('Myclass',PACKAGE='YourPackage')$Myclass

The times they are a-changin...

The application I have in mind is classes of objects representing the
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20101101/2302e9ee/attachment.htm>