#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector condSumRcpp(NumericVector x, NumericVector y, LogicalVector z) {
int n = x.length();
int sumLength = sum(z);
NumericVector res(sumLength);
int j=0;
for(int i = 0; i < n; i++) {
if (!z[i]) continue;
res[j] = x[i] + y[i];
j+=1;
}
return wrap(res);
}
This works fine when I use sourceCpp. However when I use
Rcpp.package.skeleton("testRcpp",
example_code = FALSE,
cpp_files="utils.cpp",
module=FALSE
)
and build the package with R CMD INSTALL --build testRcpp
I get
Error in .Call("testRcpp_condSumRcpp", PACKAGE = "testRcpp", x, y, z) :
"testRcpp_condSumRcpp" not available for .Call() for package "testRcpp"
If I do the same process with
// [[Rcpp::export]]
NumericVector colMaxRcpp(NumericMatrix X) {
int ncol = X.ncol();
NumericVector res(ncol);
for (int col = 0; col < ncol; col++){
res[col]=Rcpp::max(X(_, col));
}
return wrap(res);
}
then it works!
You cannot randomly mix Attributes and Rcpp.package.skeleton()
.
I usually create an empty package first (via Rcpp.package.skeleton()
or the corresponding feature in RStudio) and then add my function. Call compileAttributes()
and you should be good.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.