Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print integer vector from Rcpp function

Tags:

r

rcpp

How do I print integer vector from Rcpp function? In my function, I would like to print IntegerVector a. In R I am calling this function using for example compnz_next(5,3,c(1,2,2))

#include <Rcpp.h>

using namespace Rcpp;

// [[Rcpp::export]]
IntegerVector compnz_next(int n, int k, IntegerVector a) {
  bool more = true;
  int i;
  static int h = 0;
  static int t = 0;

  for ( i = 0; i < k; i++ ) {
    a[i] = a[i] - 1;
  }
  if ( 1 < t ) {
    h = 0;
  }

  h = h + 1;
  t = a[h-1];
  a[h-1] = 0;
  a[0] = t - 1;
  a[h] = a[h] + 1;

  more = ( a[k-1] != ( n - k ) );
  Rcout << "a vector is:" << more << std::endl;
  for ( i = 0; i < k; i++ ) {
    a[i] = a[i] + 1;
  }

  return a;
}
like image 411
Tomas Greif Avatar asked Jan 26 '15 14:01

Tomas Greif


1 Answers

Try the following line:

Rf_PrintValue(a);
like image 133
G. Grothendieck Avatar answered Sep 20 '22 19:09

G. Grothendieck