Reputation:
I am trying to build a package in R involving the Rcpp
package. When I generated the package using the command Rcpp.package.skeleton("pck338")
.
By default, the files rcpp_hello_world.cpp
is included, and the RcppExports.cpp
file is included as well.
To my understanding, the compileAttributes()
function needs to be run every time a new .cpp
function is added to the src
directory.
To that end, I wrote a simple function in the rcpp_dance.cpp
file that goes like this:
# include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp:export]]
int rcpp_dance(int x) {
int val = x + 5;
return val;
}
However, when I run the compileAttributes()
, the RcppExports.cpp
stays the same, so the dance function is not converted to an R function. Why is this happening? Any specific and general feedback would be appreciated.
Upvotes: 2
Views: 445
Reputation: 368351
In a case like this where it smells like a possible error, check for a possible error. I learned (the hard way) to first assume I goofed...
In your case: ::
!= :
.
You wanted Rcpp::export
with two colons. Try that, rinse, repeat...
(And for the other conjecture: you need to re-run compileAttributes()
each time an interface changes: adding or removing or renaming or retyping an argument in the signature, and of course adding or removing whole functions. But thankfully the function is so fast that you may as well get in the habit of running it often. If in doubt, run it.)
Upvotes: 4