EVOLUTION-MANAGER
Edit File: setRcppClass.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Create a Class Extending a C++ Class</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for setRcppClass {Rcpp}"><tr><td>setRcppClass {Rcpp}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> Create a Class Extending a C++ Class </h2> <h3>Description</h3> <p>These routines create a class definition in <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> for 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 <code><a href="exposeClass.html">exposeClass</a>()</code> will create both C++ and <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> code files to expose the C++ class. </p> <h3>Usage</h3> <pre> setRcppClass(Class, CppClass = , module = , fields = list(), contains = , methods = , saveAs = Class, where = , ...) loadRcppClass(Class, CppClass = , module = , fields = character(), contains = character(), methods = , saveAs = Class, where = , ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>Class</code></td> <td> <p>The name for the new class. </p> </td></tr> <tr valign="top"><td><code>CppClass</code></td> <td> <p>The C++ class defined in the C++ code for the package that this class extends. By default, the same as <code>Class</code>. </p> </td></tr> <tr valign="top"><td><code>module</code></td> <td> <p>The Rcpp module in which the class is defined. The module does not have to be loaded separately; <code>setRcppClass()</code> will arrange to load the module. By default, <code>"class_"</code> followed by the C++ class name. </p> <p>If <code><a href="exposeClass.html">exposeClass</a>()</code> has been called, the necessary module code will have been written in the <code>src</code> directory of the package. </p> </td></tr> <tr valign="top"><td><code>fields, contains, methods</code></td> <td> <p>Additional fields, superclasses and method definitions in <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> that extend the C++ class. These arguments are passed on to <code><a href="../../methods/html/refClass.html">setRefClass</a>()</code>. </p> </td></tr> <tr valign="top"><td><code>saveAs</code></td> <td> <p>Save a generator object for the class in the package's namespace under this name. By default, the generator object has the name of the class. To avoid saving any generator object, supply this argument as <code>NULL</code>. </p> <p>(This argument is currently needed because the actual class definition must take place at package load time, to include C++ pointer information. Therefore the value returned by <code>setRcppClass()</code> when called during package installation is not the generator object returned by <code>setRefClass()</code>. We may be able to hack around this problem in the future.) </p> </td></tr> <tr valign="top"><td><code>where</code></td> <td> <p>The environment in which to save the class definition. By default, will be the namespace of the package in which the <code>setRcppClass()</code> call is included. </p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Arguments, if any, to pass on to <code><a href="../../methods/html/refClass.html">setRefClass</a>()</code>. </p> </td></tr> </table> <h3>Details</h3> <p>The call to these functions normally appears in the source code for a package; in particular, a call is written in an <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> source file when <code><a href="exposeClass.html">exposeClass</a>()</code> is called. </p> <p><span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> code for this class or (preferably) a subclass can define new fields and methods for the class. Methods for the <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> class can refer to methods and fields defined in C++ for the C++ class, if those have been exposed. </p> <p>The fields and methods defined can include overriding C++ fields or methods. Keep in mind, however, that <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> methods can refer to C++ fields and methods, but not the reverse. If you override a C++ field or method, you essentially need to revise all code that refers to that field or method. Otherwise, the C++ code will continue to use the old C++ definition. </p> <h3>Value</h3> <p>At load time, a generator for the new class is created and stored according to the <code>saveAs</code> argument, typically under the name of the class. </p> <p>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 <code><a href="../../methods/html/refClass.html">setRefClass</a></code>. </p> <h3>Note</h3> <p>This function and function <code><a href="loadModule.html">loadModule</a>()</code> require version 2.15.0 of <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> or later, in order to use load actions, introduced in that version. </p> <p>A subtle way this can fail is by somehow loading a legitimate binary version of your package (installed under a valid version of <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span>) into a session with an older <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span>. In this case the load actions created in the binary package will simply not be called. None of the modules will be loaded and none of the classes created. </p> <p>If your symptom is that classes or other objects from modules don't exist, check the <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> version. </p> <h3>Author(s)</h3> <p>John Chambers </p> <h3>Examples</h3> <pre> ## Not run: setRcppClass("World", module = "yada", fields = list(more = "character"), methods = list( test = function(what) message("Testing: ", what, "; ", more)), saveAs = "genWorld" ) ## End(Not run) </pre> <hr /><div style="text-align: center;">[Package <em>Rcpp</em> version 1.0.5 <a href="00Index.html">Index</a>]</div> </body></html>