I have some C++ code. I would like to make this an R package with Rcpp.
Here's what I'm doing:
Rcpp.package.skeleton("myPackageName")
devtools::load_all()
to see whether rcpp_hello_world()
works after library(myPackageName)
. It does!/src
. I can still use rcpp_hello_world()
after running devtools::load_all()
once again. /src
, simply do this:(A) Put at the top of the .cpp
file `
#include <Rcpp.h>
using namespace Rcpp;
(B) Put before each function void
this comment
//[[Rcpp::export]]
Now, I foolishly think that if I run devtools::load_all()
, the code with compile and those C++ functions will be accessible. This is incorrect.
Here's the error after load_all()
:
1 warning generated.
sourcecode1.cc:2:10: fatal error: 'Rcpp.h' file not found
#include <Rcpp.h>
^
1 error generated.
make: *** [myPackageName] Error 1
ERROR: compilation failed for package ‘myPackageName’
It cannot find the header file Rcpp.h
(1) Is my procedure above incorrect in creating R packages directly from C++ code with Rcpp? This is what I've gathered from the book
(2) How can I solve this problem?
You need to run 'compileAttributes()' which RStudio would do for you too.
In short each time you alter or add interfaces, you need to run this function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With