EVOLUTION-MANAGER
Edit File: interfacesAttribute.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: Rcpp::interfaces Attribute</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 interfacesAttribute {Rcpp}"><tr><td>interfacesAttribute {Rcpp}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Rcpp::interfaces Attribute</h2> <h3>Description</h3> <p>The <code>Rcpp::interfaces</code> attribute is added to a C++ source file to specify which languages to generate bindings for from exported functions. For example: </p> <pre> // [[Rcpp::interfaces(r, cpp)]] </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>...</code></td> <td> <p>Interfaces to generate for exported functions within the source file. Valid values are <code>r</code> and <code>cpp</code>, and more than one interface can be specified. </p> </td></tr> </table> <h3>Details</h3> <p>The <code>Rcpp::interfaces</code> attribute is used to determine which bindings to generate for exported functions. The default behavior if no <code>Rcpp::interfaces</code> attribute is specified is to generate only an R interface. </p> <p>When <code>cpp</code> bindings are requested code is generated as follows: </p> <ol> <li><p> Bindings are generated into a header file located in the <code>inst/include</code> directory of the package using the naming convention <em>PackageName_RcppExports.h</em> </p> </li> <li><p> If not already present, an additional header file named <em>PackageName.h</em> is also generated which in turn includes the Rcpp exports header. </p> <p>In the case that you already have a <em>PackageName.h</em> header for your package then you can manually add an include of the Rcpp exports header to it to make the exported functions available to users of your package. </p> </li> <li><p> The generated header file allows calling the exported C++ functions without any linking dependency on the package (this is based on using the <code>R_RegisterCCallable</code> and <code>R_GetCCallable</code> functions). </p> </li> <li><p> The exported functions are defined within a C++ namespace that matches the name of the package. </p> </li></ol> <p>For example, an exported C++ function <code>foo</code> could be called from package <code>MyPackage</code> as follows: </p> <pre> // [[Rcpp::depends(MyPackage)]] #include <MyPackage.h> void foo() { MyPackage::bar(); } </pre> <p>The above example assumes that the <code>sourceCpp</code> function will be used to compile the code. If rather than that you are building a package then you don't need to include the <code>Rcpp::depends</code> attribute, but instead should add an entry for the referenced package in the <code>Depends</code> and <code>LinkingTo</code> fields of your package's <code>DESCRIPTION</code> file. </p> <h3>Note</h3> <p>If a file by the name of <em>PackageName.h</em> that wasn't generated by <code>compileAttributes</code> already exists in in the <code>inst/include</code> directory then it will not be overwritten (rather, an error will occur). </p> <p>A static naming scheme for generated header files and namespaces is used to ensure consistent usage semantics for clients of exported <code>cpp</code> interfaces. Packages that wish to export more complex interfaces or additional C++ types are therefore typically better off not using this mechanism. </p> <p>The <code>Rcpp::interfaces</code> attribute is specified using a syntax compatible with the new <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2761.pdf">generalized attributes</a> feature of the C++11 standard. Note however that since this feature is not yet broadly supported by compilers it needs to be specified within a comment (see examples below). </p> <h3>See Also</h3> <p><code><a href="compileAttributes.html">compileAttributes</a></code>, <code><a href="exportAttribute.html">Rcpp::export</a></code>, <code><a href="dependsAttribute.html">Rcpp::depends</a></code> </p> <h3>Examples</h3> <pre> ## Not run: // [[Rcpp::interfaces(r, cpp)]] ## 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>