Art
Art

Reputation: 21

How to rewrite a c++ function from an R package

I am using the compute_iterative_ratings function from the R package "comperank": https://github.com/cran/comperank/blob/master/src/RcppExports.cpp

I would like to modify this function so that it accepts one more argument (an integer variable called amateur), so that the function becomes:

compute_iterative_ratings(rate_fun, player1_id, score1, player2_id, score2, initial_ratings, amateur)

I'd like to just copy the cpp file, modify it to accept the extra argument, and then save it into my working directory so that I can then call sourceCpp for when I need it. This is all new territory for me so I'm not sure what I'm supposed to edit. I also do not know what the final 2 blocks of code mean.

static const R_CallMethodDef CallEntries[] = {
    {"_comperank_compute_iterative_ratings", (DL_FUNC) &_comperank_compute_iterative_ratings, 6},
    {NULL, NULL, 0}
};

RcppExport void R_init_comperank(DllInfo *dll) {
    R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
    R_useDynamicSymbols(dll, FALSE);
}

Upvotes: 1

Views: 358

Answers (2)

Ralf Stubner
Ralf Stubner

Reputation: 26843

The code you are looking at is autogenerated. This code will be updated when you adjust the corresponding C++ function and call Rcpp::compileAttributes within the package. So instead of RcppExports.cpp you should edit iterative-ratings.cpp. This is also true when using Rcpp::sourceCpp.

Upvotes: 2

Andrey Shabalin
Andrey Shabalin

Reputation: 4614

The only part there you'll need to change is the number 6 to 7, as it informs R about the number of parameters in the function _comperank_compute_iterative_ratings.

static const R_CallMethodDef CallEntries[] = {
    {"_comperank_compute_iterative_ratings", (DL_FUNC) &_comperank_compute_iterative_ratings, 7},
    {NULL, NULL, 0}
};

For more information see https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Registering-native-routines

Upvotes: 0

Related Questions