c++ - Rcpp error with sugar all() line -
i've written code r rcpp , c++ try , become more familiar it:
#include <rcpp.h> #include <vector> using namespace rcpp; // [[rcpp::export]] charactermatrix reduce_sequences(charactermatrix completedna) { std::vector<int> informativesites; for(int = 0; < completedna.ncol(); i++) { charactervector bpsite(completedna.nrow()); for(int n = 0; n < completedna.nrow(); n++) { bpsite[n] = completedna(n,i); } if(any(bpsite != bpsite[0]).is_true()) informativesites.push_back(i); } charactermatrix cutdna(3, informativesites.size()); for(int = 0; < informativesites.size(); i++) { for(int n = 0; n < cutdna.nrow(); n++) { cutdna(n,i) = completedna(n,informativesites[i]); } } return cutdna; }
but comple error not source file, comparator_with_one_value.h:
i won't pretend understand these errors because i'm still in c++ infancy, commenting out code suitably , finding causes it, line 17:
if(any(bpsite != bpsite[0]).is_true()) informativesites.push_back(i);
i think has me using any(). i'm doing wrong?
edit: changed lines reflect issues above resolved except two: console output:
error in rcpp::sourcecpp("reduceseq.cpp") : error 1 occurred building shared library.
issues returned comparator_with_one_value.h operands ?: have different types 'sexprec*' , 'int'
, invalid conversion 'sexprec* const' 'int'
thanks, ben.
we prevent on purpose because of 3 values logical in r
: true
, false
, na
. should able use is_true
:
if(any(bpsite != bpsite[0]).is_true()) informativesites.push_back(i);
Comments
Post a Comment