Skip to content

[Rcpp-devel] Problems with Rcout

2 messages · Iñaki Ucar, Barth Riley

#
On Tue, 27 Nov 2018 at 17:06, Barth Riley <barthriley at comcast.net> wrote:
The contents of the function are irrelevant. If I compile and execute
this in a clean session, it works fine. I.e.:

Rcpp::cppFunction('
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;
}
')

getValidCount(matrix(), FALSE)
#> getValidCount BEGINS
#> Treating as matrix
#> [1] 0

So where are you calling this? Are you redirecting the stdout? Are you
parallelising, are you calling this inside a subprocess?

I?aki
#
Thanks for your reply. No, I?m not calling this using parallelization, and to my knowledge at least I have not redirected stdout (how would I check this?). The function is meant to be called by another function, but I am testing it directly from the R console.

Barth
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20181127/e37f8662/attachment.html>