cpp11 helps you to interact with R objects using C++ code. Its goalsand syntax are similar to the excellentRcpp package.
To add cpp11 to an existing package, put your C++ files in thesrc/ directory and add the following to your DESCRIPTIONfile:
LinkingTo: cpp11Then decorate C++ functions you want to expose to R with[[cpp11::register]].Note that this is aC++11attribute, not a comment like is used in Rcpp.
cpp11 is a header only library with no hard dependencies and does notuse a shared library, so it is straightforward and reliable to use inpackages without fear of compile-time and run-time mismatches.
Alternatively, you canvendorthe current installed version of cpp11 headers into your package withcpp11::vendor_cpp11(). This ensures the headers will remainunchanged until you explicitly update them.
Seevignette(“cpp11”)to get started using cpp11 in your scripts, particularly if you are newto C++ programming.
Posit Community is the bestplace to ask for help using cpp11 or interfacing C++ with R.
Rcpp has been awidely successful project, however over the years a number of issues andadditional C++ features have arisen. Adding these features to Rcpp wouldrequire a great deal of work, or in some cases would be impossiblewithout severely breaking backwards compatibility.
cpp11 is a ground up rewrite of C++ bindings to Rwith different design trade-offs and features.
Changes that motivated cpp11 include:
Seevignette(“motivations”)for full details on the motivations for writing cpp11.
Seevignette(“converting”)if you are already familiar with Rcpp or have an existing package thatuses Rcpp and want to convert it to use cpp11.
Seevignette(“internals”)for details on the cpp11 implementation or if you would like tocontribute to cpp11.
Please note that the cpp11 project is released with aContributor Code ofConduct. By contributing to this project, you agree to abide by itsterms.
cpp11 would not exist without Rcpp. Thanks to the Rcpp authors, DirkEddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey, Qiang Kou,Nathan Russell, Douglas Bates and John Chambers for their work writingand maintaining Rcpp.