2

I have a series of vectors which I am adding into a DataFrame object to return to R. The problem comes when I try and add a vector with long long elements.

// [[Rcpp::export]]
DataFrame test()
{
std::vector<long long> x;
return DataFrame::create(Named("x") = x);
}

The error returned is

g++ -m64 -I"C:/R/R-30~1.1/include" -DNDEBUG -I"C:/R/R-3.0.1/library/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -mtune=core2 -c quotes.cpp -o quotes.o In file included from C:/R/R-3.0.1/library/Rcpp/include/RcppCommon.h:117:0, from C:/R/R-3.0.1/library/Rcpp/include/Rcpp.h:27, from quotes.cpp:1: C:/R/R-3.0.1/library/Rcpp/include/Rcpp/internal/wrap.h: In function 'SEXPREC* Rcpp::internal::wrap_dispatch_unknown_iterable(const T&, Rcpp::traits::false_type) [with T = long long int, SEXP = SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant]': C:/R/R-3.0.1/library/Rcpp/include/Rcpp/internal/wrap.h:691:98: instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch_unknown(const T&, Rcpp::traits::false_type) [with T = long long int, SEXP = SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant]' C:/R/R-3.0.1/library/Rcpp/include/Rcpp/internal/wrap.h:723:96: instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch_eigen(const T&, Rcpp::traits::false_type) [with T = long long int, SEXP = SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant]' C:/R/R-3.0.1/library/Rcpp/include/Rcpp/internal/wrap.h:740:80: instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch_unknown_importable(const T&, Rcpp::traits::false_type) [with T = long long int, SEXP = SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant]' C:/R/R-3.0.1/library/Rcpp/include/Rcpp/internal/wrap.h:760:99: instantiated from 'SEXPREC* Rcpp::internal::wrap_dispatch(const T&, Rcpp::traits::wrap_type_unknown_tag) [with T = long long int, SEXP = SEXPREC*]' C:/R/R-3.0.1/library/Rcpp/include/Rcpp/internal/wrap.h:863:104: instantiated from 'SEXPREC* Rcpp::wrap(const T&) [with T = long long int, SEXP = SEXPREC*]' C:/R/R-3.0.1/library/Rcpp/include/Rcpp/internal/wrap.h:193:3: [ skipping 14 instantiation contexts ] C:/R/R-3.0.1/library/Rcpp/include/Rcpp/vector/Vector.h:395:9: instantiated from 'static void Rcpp::Vector::replace_element__dispatch(Rcpp::traits::true_type, Rcpp::Vector::iterator, SEXP, int, const U&) [with U = Rcpp::traits::named_object >, int RTYPE = 19, Rcpp::traits::true_type = Rcpp::traits::integral_constant, Rcpp::Vector::iterator = Rcpp::internal::Proxy_Iterator >, SEXP = SEXPREC*]' C:/R/R-3.0.1/library/Rcpp/include/Rcpp/vector/Vector.h:384:9: instantiated from 'static void Rcpp::Vector::replace_element(Rcpp::Vector::iterator, SEXP, int, const U&) [with U = Rcpp::traits::named_object >, int RTYPE = 19, Rcpp::Vector::iterator = Rcpp::internal::Proxy_Iterator >, SEXP = SEXPREC*]' C:/R/R-3.0.1/library/Rcpp/include/Rcpp/generated/Vector_create.h:318:2: instantiated from 'static Rcpp::Vector Rcpp::Vector::create_dispatch(Rcpp::traits::true_type, const T1&, const T2&, const T3&, const T4&, const T5&, const T6&) [with T1 = Rcpp::traits::named_object >, T2 = Rcpp::traits::named_object >, T3 = Rcpp::traits::named_object >, T4 = Rcpp::traits::named_object >, T5 = Rcpp::traits::named_object >, T6 = Rcpp::traits::named_object >, int RTYPE = 19, Rcpp::Vector = Rcpp::Vector<19>, Rcpp::traits::true_type = Rcpp::traits::integral_constant]' C:/R/R-3.0.1/library/Rcpp/include/Rcpp/generated/Vector__create.h:288:37: instantiated from 'static Rcpp::Vector Rcpp::Vector::create(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&) [with T1 = Rcpp::traits::named_object >, T2 = Rcpp::traits::named_object >, T3 = Rcpp::traits::named_object >, T4 = Rcpp::traits::named_object >, T5 = Rcpp::traits::named_object >, T6 = Rcpp::traits::named_object >, int RTYPE = 19, Rcpp::Vector = Rcpp::Vector<19>]' C:/R/R-3.0.1/library/Rcpp/include/Rcpp/generated/DataFrame_generated.h:59:73: instantiated from 'static Rcpp::DataFrame Rcpp::DataFrame::create(const T1&, const T2&, const T3&, const T4&, const T5&, const T6&) [with T1 = Rcpp::traits::named_object >, T2 = Rcpp::traits::named_object >, T3 = Rcpp::traits::named_object >, T4 = Rcpp::traits::named_object >, T5 = Rcpp::traits::named_object >, T6 = Rcpp::traits::named_object >, Rcpp::DataFrame = Rcpp::DataFrame]' quotes.cpp:58:26: instantiated from here C:/R/R-3.0.1/library/Rcpp/include/Rcpp/internal/wrap.h:474:11: error: invalid conversion from 'long long int' to 'SEXP' [-fpermissive] make: * [quotes.o] Error 1 .

Is there a way to add a vector of this type into a DataFrame?

Craig
  • 413
  • 7
  • 16
  • 1
    @CauchyDistributedRV not anymore `RJSONIO::fromJSON('[12345678912]')` give `[1] 1.2346e+10` – dickoa Jul 09 '13 at 23:27
  • The best way to achieve this is extend `Rcpp` by writing your own `wrap` for long long vector www.cran.r-project.org/web/packages/Rcpp/vignettes/Rcpp-extending.pdf – dickoa Jul 09 '13 at 23:30

1 Answers1

6

There is not, sadly, as CRAN only allows a C standard without long long.

Also, R itself only has numeric (aka double) and integer. So I would suggest you just use double as a type.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Thank you for your answer, I ended up using unsigned integer, and everything works as expected. – Craig Jul 10 '13 at 19:49
  • 1
    R only has signed ints though, so you're going to have overflow problems if you're putting any values greater than `2^31-1` in there. If you need the extra precision, use `double`. See also: http://stackoverflow.com/questions/2053397/long-bigint-decimal-equivalent-datatype-in-r – Kevin Ushey Jul 11 '13 at 06:28
  • Craig: And feel free to 'accept' the answer by clicking on the tickmark and/or upvote it. As @CauchyDistributedRV mentioned, uint has issues as R does not have it. I still recommend double. – Dirk Eddelbuettel Jul 11 '13 at 07:57