[Rcpp-devel] Problems with Rcout

Barth Riley barthriley at comcast.net
Tue Nov 27 17:06:47 CET 2018


Here is a more complete example. Note that I want to output text strings for debugging purposes as the code for treatAsVector = true is never executed.

Barth

NumericVector getValidCount(Rcpp::NumericMatrix m, 
                            bool treatAsVector) {
  
  Rcpp::Rcout << "getValidCount BEGINS" << std::endl;
  
  int N = m.cols();
  NumericVector u, vec;
  NumericVector count (N);  

  if(!treatAsVector) {
    Rcpp::Rcout << "Treating as matrix" << std::endl;
    for(int i = 0; i < N; i++) {
      vec = m(_,i);
      vec = vec[!Rcpp::is_na(vec)];
      u = Rcpp::unique(vec);
      count[i] = u.length();
    }    
  } else {
    Rcpp::Rcout << "treating as vector" << std::endl;
    vec = as<NumericVector>(m);
    vec = vec[!Rcpp::is_na(vec)];
    u = Rcpp::unique(vec);

    count.fill(u.length());
  }

  return count;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20181127/ddb3d2d4/attachment.html>


More information about the Rcpp-devel mailing list