[Rcpp-devel] [R-pkg-devel] moving from C to C++ with Rcpp in R package
On 2 June 2022 at 19:27, Jean Thioulouse wrote:
|
| But it seems that the C_ prefix must be added to _myPackage_myFunctionName (to get for example C__ade4_RVrandtestCpp) in the RcppExports.R file. So where should I modify the Rcpp::export tag ?
Just how I wrote it below: inside the parens of the Rcpp::export tag.
A full worked example is
#include <Rcpp.h>
// [[Rcpp::export(C_foo)]]
bool foo() {
return true;
}
/*** R
C_foo()
*/
which when I sourceCpp() it does indeed do as it is told:
> Rcpp::sourceCpp("/tmp/foo.cpp")
> C_foo()
[1] TRUE
>
A quick grep here did not reveal an actual example of where I prefix with C_
but for example in the RcppSimdJson package we use this a little bit to
massage function names and control what is, or isn't, visible and exported on
the R side:
edd at rob:~/git$ grep Rcpp::export rcppsimdjson/src/*cpp
rcppsimdjson/src/deserialize.cpp:// [[Rcpp::export(.deserialize_json)]]
rcppsimdjson/src/deserialize.cpp:// [[Rcpp::export(.load_json)]]
rcppsimdjson/src/deserialize.cpp:// [[Rcpp::export(.exceptions_enabled)]]
rcppsimdjson/src/exported-utils.cpp:// [[Rcpp::export(is_valid_json)]]
rcppsimdjson/src/exported-utils.cpp:// [[Rcpp::export(is_valid_utf8)]]
rcppsimdjson/src/exported-utils.cpp:// [[Rcpp::export(fminify)]]
rcppsimdjson/src/internal-utils.cpp:// [[Rcpp::export(.is_valid_json_arg)]]
rcppsimdjson/src/internal-utils.cpp:// [[Rcpp::export(.is_valid_query_arg)]]
rcppsimdjson/src/internal-utils.cpp:// [[Rcpp::export(.diagnose_input)]]
rcppsimdjson/src/rcppsimdjson_utils_check.cpp:// [[Rcpp::export(.check_int64)]]
rcppsimdjson/src/simdjson_example.cpp:// [[Rcpp::export(.validateJSON)]]
rcppsimdjson/src/simdjson_example.cpp:// [[Rcpp::export]]
rcppsimdjson/src/simdjson_example.cpp:// [[Rcpp::export(.cppVersion)]]
rcppsimdjson/src/simdjson_example.cpp:// [[Rcpp::export(.unsupportedArchitecture)]]
edd at rob:~/git$
Hope this helps, Dirk
| Thanks
| Jean
|
|
| > Le 2 juin 2022 à 15:49, Dirk Eddelbuettel <edd at debian.org> a écrit :
| >
| >
| > On 2 June 2022 at 08:32, Dirk Eddelbuettel wrote:
| > | | > | (Removed CC to r-package-devel) | > |
| > | On 2 June 2022 at 16:24, Ivan Krylov wrote:
| > | | Unfortunately, this means editing RcppExports.R, which (I think) | > | | prevents you from enjoying the way Rcpp::compileAttributes() sets | > | | everything up for you. | > | | > | Yes. I think that is the best I came up with once too in a time of need in a | > | package actively mixing C and C++. It simply is easier to have just C++, and | > | I think you generally can just convert your C files. | > | > PS One thing that works is to rename in the Rcpp::export tag ie | > | > // [[Rcpp::export(C_my_func_name)]] | > | > can be used to prefix C_ to a function my_func_name(). | > | > Dirk | > | > -- | > dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org | > _______________________________________________ | > Rcpp-devel mailing list | > Rcpp-devel at lists.r-forge.r-project.org | > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel |
dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org