r - Building packages with Rcpp, Attributes not handled correctly -
i've been playing around setting r package aims make use of rcpp in rstudio, i'm struggling things work rcpp attributes.
my understanding of how works tenuous, understanding follows:
- in source c++ files, can add rcpp attributes, example tag
// [[rcpp::export]]
marks c++ function exporting, making available r. - when build package,
rcpp
generates appropriate c++ code in filercppexports.cpp
, , wrapper functions in r source filercppexports.r
.
this doesn't seem working (as expect) when build package. roxygen isn't playing nicely when generating namespace file (so i've disabled that). tag // [[rcpp::export]]
seems mark function exporting r, rather marking function being exported package namespace.
more importantly, rcpp attribute tag // [[rcpp::depends()]]
isn't being handled correctly. if copy code here new source file, , rebuild package, gcc
throws errors on rcppexports.cpp
file saying bigmatrix
identifier undeclared indicating attribute tage // [[rcpp::depends(bigmemory)]]
isn't being handled correctly.
since multiple things aren't working expect, missing in understanding of rcpp attribute tags?
this issue rcppexports.cpp
file generated. @ moment, there no way teach include header files somewhere else, not include bigmemory/matrixaccessor.hpp
.
a workaround this:
#include <rcpp.h> #include <bigmemory/matrixaccessor.hpp> rcpp::numericvector bigcolsums(rcpp::xptr<bigmatrix> pbigmat) { // create matrix accessor can @ elements of matrix. matrixaccessor<double> ma(*pbigmat); // create vector we'll store column sums in. rcpp::numericvector colsums(pbigmat->ncol()); (size_t i=0; < pbigmat->ncol(); ++i) colsums[i] = std::accumulate(ma[i], ma[i]+pbigmat->nrow(), 0.0); return colsums; } // [[rcpp::export]] rcpp::numericvector bigcolsums( sexp pbigmat ){ return bigcolsums( rcpp::xptr<bigmatrix>( pbigmat) ) ; }
so capture type in .cpp
file , rcppexports.cpp
has know sexp
.
Comments
Post a Comment