EVOLUTION-MANAGER
Edit File: exportAttribute.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::export 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 exportAttribute {Rcpp}"><tr><td>exportAttribute {Rcpp}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Rcpp::export Attribute</h2> <h3>Description</h3> <p>The <code>Rcpp::export</code> attribute is added to a C++ function definition to indicate that it should be made available as an R function. The <code><a href="sourceCpp.html">sourceCpp</a></code> and <code><a href="compileAttributes.html">compileAttributes</a></code> functions process the <code>Rcpp::export</code> attribute by generating the code required to call the C++ function from R. </p> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>name</code></td> <td> <p>Specify an alternate name for the generated R function (optional, defaults to the name of the C++ function if not specified). </p> </td></tr> </table> <h3>Details</h3> <p>Functions marked with the <code>Rcpp::export</code> attribute must meet several conditions to be correctly handled: </p> <ol> <li><p> Be defined in the global namespace (i.e. not within a C++ <code>namespace</code> declaration). </p> </li> <li><p> Have a return type that is either void or compatible with <code>Rcpp::wrap</code> and parameter types that are compatible with <code>Rcpp::as</code> (see sections 3.1 and 3.2 of the <em>Rcpp-introduction</em> vignette for more details). </p> </li> <li><p> Use fully qualified type names for the return value and all parameters. However, Rcpp types may appear without the namespace qualifier (i.e. <code>DataFrame</code> is okay as a type name but <code>std::string</code> must be specified fully). </p> </li></ol> <p>If default argument values are provided in the C++ function definition then these defaults are also used for the exported R function. For example, the following C++ function: </p> <pre> DataFrame readData( CharacterVector file, CharacterVector exclude = CharacterVector::create(), bool fill = true) </pre> <p>Will be exported to R as: </p> <pre> function (file, exclude = character(0), fill = TRUE) </pre> <p>Note that C++ rules for default arguments still apply: they must occur consecutively at the end of the function signature and unlike R can't rely on the values of other arguments. </p> <h3>Note</h3> <p>When a C++ function has export bindings automatically generated by the <code><a href="compileAttributes.html">compileAttributes</a></code> function, it can optionally also have a direct C++ interface generated using the <code><a href="interfacesAttribute.html">Rcpp::interfaces</a></code> attribute. </p> <p>The <code>Rcpp::export</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="sourceCpp.html">sourceCpp</a></code> and <code><a href="compileAttributes.html">compileAttributes</a></code> </p> <h3>Examples</h3> <pre> ## Not run: #include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] int fibonacci(const int x) { if (x == 0) return(0); if (x == 1) return(1); return (fibonacci(x - 1)) + fibonacci(x - 2); } // [[Rcpp::export("convolveCpp")]] NumericVector convolve(NumericVector a, NumericVector b) { int na = a.size(), nb = b.size(); int nab = na + nb - 1; NumericVector xab(nab); for (int i = 0; i < na; i++) for (int j = 0; j < nb; j++) xab[i + j] += a[i] * b[j]; return xab; } ## 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>