ShanZhengYang ShanZhengYang - 2 years ago 74
C++ Question

Rcpp: porting C++ function into R, 'Rcpp.h' file not found

I have some C++ code. I would like to make this an R package with Rcpp.

Here's what I'm doing:

  1. Create a package framework by executing

  2. Run
    to see whether
    works after
    . It does!

  3. Take all C++ source code and copy this into
    . I can still use
    after running
    once again.

  4. For each function in the C++ source code now residing in
    , simply do this:

(A) Put at the top of the
file `

#include <Rcpp.h>
using namespace Rcpp;

(B) Put before each function
this comment


Now, I foolishly think that if I run
, the code with compile and those C++ functions will be accessible. This is incorrect.

Here's the error after

1 warning generated. 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

(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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download