Rcpp (version 0.12.9)

interfacesAttribute: Rcpp::interfaces Attribute

Description

The Rcpp::interfaces attribute is added to a C++ source file to specify which languages to generate bindings for from exported functions. For example:
// [[Rcpp::interfaces(r, cpp)]]

Arguments

...
Interfaces to generate for exported functions within the source file. Valid values are r and cpp, and more than one interface can be specified.

Details

The Rcpp::interfaces attribute is used to determine which bindings to generate for exported functions. The default behavior if no Rcpp::interfaces attribute is specified is to generate only an R interface. When cpp bindings are requested code is generated as follows:

  1. Bindings are generated into a header file located in the inst/include directory of the package using the naming convention PackageName_RcppExports.h
  2. If not already present, an additional header file named PackageName.h is also generated which in turn includes the Rcpp exports header. In the case that you already have a PackageName.h 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.
  3. The generated header file allows calling the exported C++ functions without any linking dependency on the package (this is based on using the R_RegisterCCallable and R_GetCCallable functions).
  4. The exported functions are defined within a C++ namespace that matches the name of the package.

For example, an exported C++ function foo could be called from package MyPackage as follows:

   // [[Rcpp::depends(MyPackage)]]

#include

void foo() { MyPackage::bar(); }

The above example assumes that the sourceCpp 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 Rcpp::depends attribute, but instead should add an entry for the referenced package in the Depends and LinkingTo fields of your package's DESCRIPTION file.

See Also

compileAttributes, Rcpp::export, Rcpp::depends

Examples

Run this code
## Not run: 
# 
# // [[Rcpp::interfaces(r, cpp)]]
# ## End(Not run)

Run the code above in your browser using DataCamp Workspace