Learn R Programming

Rcpp (version 0.10.6)

setRcppClass: Create a Class Extending a C++ Class

Description

These routines create a class definition in Rfor an exposed C++ class, setting up and executing a load action to incorporate the C++ pointer information. Neither function should normally need to be called directly; for most applications, a call to exposeClass() will create both C++ and Rcode files to expose the C++ class.

Usage

setRcppClass(Class, CppClass = , module = , fields = list(), contains = ,
             methods = , saveAs = Class, where = , ...)
loadRcppClass(Class, CppClass = , module = , fields = character(),
              contains = character(),
              methods = , saveAs = Class, where = , ...)

Arguments

Class
The name for the new class.
CppClass
The C++ class defined in the C++ code for the package that this class extends. By default, the same as Class.
module
The Rcpp module in which the class is defined. The module does not have to be loaded separately; setRcppClass() will arrange to load the module. By default, "class_" followed by the C++ class name.

If

fields, contains, methods
Additional fields, superclasses and method definitions in R

Value

  • At load time, a generator for the new class is created and stored according to the saveAs argument, typically under the name of the class.

    The value returned at installation time is a dummy. Future revisions of the function may allow us to return a valid generator at install time. We recommend using the standard style of assigning the value to the name of the class, as one would do with setRefClass.

item

  • saveAs
  • where
  • ...

Details

The call to these functions normally appears in the source code for a package; in particular, a call is written in an Rsource file when exposeClass() is called.

R

Examples

Run this code
setRcppClass("World", 
    module = "yada", 
    fields = list(more = "character"),
    methods = list(
        test = function(what) message("Testing: ", what, "; ", more)),
    saveAs = "genWorld"
         )

Run the code above in your browser using DataLab