Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compileAttributes doesn't copy the local header to RcppExports.cpp

Tags:

r

rcpp

Here is my R_API.cpp

#include "include/R_GatingSet.hpp" 
#include <Rcpp.h>

Rcpp::List getPopCounts(Rcpp::XPtr<GatingSet> gsPtr, StringVec sampleNames, StringVec subpopulation, bool flowJo, bool isFullPath){
//do stuff
}

And here is RcppExports.cpp generated by compileAttributes

#include <Rcpp.h>
using namespace Rcpp;

// getPopCounts
Rcpp::List getPopCounts(Rcpp::XPtr<GatingSet> gsPtr, StringVec sampleNames, StringVec subpopulation, bool flowJo, bool isFullPath);
RcppExport SEXP flowWorkspace_getPopCounts(SEXP gsPtrSEXP, SEXP sampleNamesSEXP, SEXP subpopulationSEXP, SEXP flowJoSEXP, SEXP isFullPathSEXP) {
BEGIN_RCPP
    SEXP __sexp_result;
    {
        Rcpp::RNGScope __rngScope;
        Rcpp::traits::input_parameter< Rcpp::XPtr<GatingSet> >::type gsPtr(gsPtrSEXP );
    Rcpp::traits::input_parameter< StringVec >::type sampleNames(sampleNamesSEXP );
}

Apparently this fails the compiler because it misses the local header include (R_GatingSet.hpp) that defines the user class GatingSet.

g++ -I/home/wjiang2/R/r-devel/build/include -DNDEBUG -DROUT -Wno-deprecated -I/home/wjiang2/mylib/include/libxml2  -Ibst/ -I/usr/local/include -I"/home/wjiang2/R/r-devel/build/library/Rcpp/include"   -fpic  -g -O2  -c RcppExports.cpp -o RcppExports.o
RcppExports.cpp:9:36: error: ‘GatingSet’ was not declared in this scope

I wonder if there is better solution other than manually adding this include back to RcppExports.cpp?

like image 586
Mike Jiang Avatar asked Aug 25 '14 20:08

Mike Jiang


1 Answers

You should be able to handle this by having a header file of the same name as your package in (assuming the package is flowWorkspace):

inst/include/flowWorkspace.h

compileAttributes will include that header file in RcppExports.cpp, and in there you could include the definitions of classes you need for the rest of the exports machinery to work.

EDIT: You could also try using the // [[Rcpp::interfaces(r, cpp)]] attribute to auto-generate these interfaces for you (although I haven't played around with that as much), but it is discussed in the Rcpp Attributes vignette -- see 3.5.1.

like image 65
Kevin Ushey Avatar answered Nov 18 '22 12:11

Kevin Ushey