#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!