Andrej
Andrej

Reputation: 3849

Unimplemented type 'builtin' in 'coerceToReal' [Rcpp]

I have just started with Rcpp. I have a simple program which takes two numerical vectors, computes their union and returns a numerical vector. The listing is pasted below (test.cpp).

#include <Rcpp.h>
#include <algorithm>
using namespace Rcpp;

// [[Rcpp::export]]
NumericVector test(NumericVector x, NumericVector y) {
  int n = x.size() + y.size();
  std::vector<int> v(n);
  std::vector<int>::iterator it;

  std::sort(x.begin(), x.end());
  std::sort(y.begin(), y.end());

  it=std::set_union(x.begin(), x.end(), y.begin(), y.end(), v.begin());
  v.resize(it-v.begin());

  return wrap(v);
}


/*** R
x <- c(5,10,15,20,25)
y <- c(50,40,30,20,10)
test(x, y)
*/

When I try to run the program with values

x <- sample(20000)
y <- sample(20000)
test(x, y)

the function works. But when I increase number of values

x <- sample(1000000)
y <- sample(1000000)
test(x, y)

the program crashes with the output

Error in .Primitive(".Call")(<pointer: 0x7f1819d8af20>, x, y) : 
  unimplemented type 'builtin' in 'coerceToReal'

Any ideas what is happening? Thanks for any pointer or reference.

Upvotes: 2

Views: 145

Answers (1)

F. Priv&#233;
F. Priv&#233;

Reputation: 11738

Replace your NumericVectors by IntegerVectors. Or work with std::vector<double>.

Upvotes: 2

Related Questions