If the code
parameter is provided then the file
parameter is ignored. Functions exported using sourceCpp
must meet several conditions, including being defined in the global namespace and having return types that are compatible with Rcpp::wrap
and parameter types that are compatible with Rcpp::as
. See the Rcpp::export
documentation for more details.
If the source file has compilation dependencies on other packages (e.g. Matrix, RcppArmadillo) then an Rcpp::depends
attribute should be provided naming these dependencies.
It's possible to embed chunks of R code within a C++ source file by including the R code within a block comment with the prefix of /*** R
. For example:
/*** R
# Call the fibonacci function defined in C++
fibonacci(10)
*/
Multiple R code chunks can be included in a C++ file. All R code is sourced after the C++ functions within the file have been defined.