[Rcpp-devel] Local .h files and Rcpp attributes

Romain Francois romain at r-enthusiasts.com
Sat Oct 19 17:55:32 CEST 2013


Le 19/10/13 05:13, Mark Fredrickson a écrit :
> Hello,
>
> Short version: Is it possible to instruct the code generator in
> `compileAttributes` to source local header files when generating
> RcppExports.cpp?
>
> Long version: I'm trying to crib from the Dirk's examples in his recent
> UCB talk examples about function pointers
> (http://dirk.eddelbuettel.com/papers/rcpp_booth_uofc_oct2013-part2.pdf).
> In it, he uses a `typedef` to define the type of his function call. This
> is all great if using `sourceCpp` to slurp in the file directly, but I'm
> getting errors when compiling a package. I'd like to use attributes to
> export my functions at both the R level and as the target of function
> pointers, but this may be incompatible with attributes, at least at some
> level.
>
> My (perhaps naive) attempts are giving errors about my `funcPtr` type
> not being defined. I've tried moving this definition to a header file,
> but even with `//[[Rcpp::depends(myheader)]]` or
> `\\[Rcpp::depends(myheader.h)]]`, the generated RcppExports.cpp file
> does not include `myheader.h`.
>
> My (non-working) code can be found at:
>
> https://github.com/markmfredrickson/RItools/blob/ri-rcpp/src/teststatistics.cpp
>
> Thanks in advance,
>
> -M

Hello,

Try putting your declarations into a RItools.h file in inst/include/ or 
src/ in your package, i.e. have this in RItools.h

typedef double (*testStat)(NumericVector, NumericVector);

and add:

PKG_CPPFLAGS += -I../inst/include/

to your Makevars and Makevars.win.

Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30



More information about the Rcpp-devel mailing list