I'm trying to pass a vector of bool as an argument to a function using Rcpparmadillo. A silly example looks like this:
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
// [[Rcpp::export]]
arma::mat myfun(arma::mat A, arma::vec mybool)
{
int n = A.n_rows;
arma::vec B(n);
for(unsigned int i = 0; i < n; ++i)
{
if(mybool.row(i) && i < 10) // mybool.row(i) && throws the error
{
B.row(i) = arma::accu(A.row(i));
}
else
{
B.row(i) = pow(arma::accu(A.row(i)), 0.5);
}
}
return B;
}
Here a mat<unsigned char>
type is suggested but doesn't work for me. I've tried uvec
and std::vector<bool>
as well but doesn't work either. What is the best way to pass a logical vector as an argument using Rcpparmadillo
?