我有一系列 vector ,这些 vector 要添加到DataFrame对象中以返回到R。
当我尝试添加具有长而长的元素的 vector 时,问题就来了。
// [[Rcpp::export]]
DataFrame test()
{
std::vector<long long> x;
return DataFrame::create(Named("x") = x);
}
返回的错误是
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在C:/R/R-3.0.1/library/Rcpp/include/RcppCommon.h包含的文件中: 117:0,来自C:/R/R-3.0.1/library/Rcpp/include/Rcpp.h:27,来自quotes.cpp:1:C:/R/R-3.0.1/library/Rcpp/ include / Rcpp / internal / wrap.h:在函数'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:从'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:从'SEXPREC * Rc实例化pp::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:从'SEXPREC * Rcpp::internal::wrap_dispatch_unknown_importable(const T&,Rcpp::traits::false_type)[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:从'SEXPREC * Rcpp::internal::wrap_dispatch(const T&,Rcpp::traits::wrap_type_unknown_tag)实例化[T = long long int,SEXP = SEXPREC *]'C :/R/R-3.0.1/library/Rcpp/include/Rcpp/internal/wrap.h:863:104:从'SEXPREC * Rcpp::wrap(const T&)实例化[T = long long int,SEXP = SEXPREC *]'C:/R/R-3.0.1/library/Rcpp/include/Rcpp/internal/wrap.h:193:3:[跳过14个实例化上下文] C:/R/R-3.0.1 /library/Rcpp/include/Rcpp/vector/Vector.h:395:9:Instanti从'static void Rcpp::Vector::replace_element__dispatch(Rcpp::traits::true_type,Rcpp::Vector::iterator,SEXP,int,const U&)(使用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:从'static void Rcpp::Vector::replace_element(Rcpp::Vector::iterator,SEXP,int,const U&)实例化[使用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:从“静态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_ob ject>,T5 = Rcpp::traits::named_object>,T6 = Rcpp::traits::named_object>,int RTYPE = 19,Rcpp::Vector = Rcpp::Vector ,Rcpp::traits::true_type = Rcpp::traits::integral_constant]'C:/R/R-3.0.1/library/Rcpp/include/Rcpp/Generated/Vector__create.h:288:37:从“静态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 ]'C:/R/R-3.0.1/library/Rcpp/include/Rcpp/generated/DataFrame_genic.h:59:73:从“静态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::nam ed_object>,T5 = Rcpp::traits::named_object>,T6 = Rcpp::traits::named_object>,Rcpp::DataFrame = Rcpp::DataFrame]'quotes.cpp:58:26:从此处实例化C:/ R / R-3.0.1 / library / Rcpp / include / Rcpp / internal / wrap.h:474:11:错误:从'long long int'到'SEXP'的无效转换[-fpermissive]使:* [引号。 o]错误1。
有没有一种方法可以将这种类型的 vector 添加到DataFrame中?
最佳答案
遗憾的是,没有,因为CRAN只允许C标准而已。
同样,R本身仅具有数字(也称为 double )和整数。因此,我建议您只使用double作为类型。
关于c++ - Rcpp,使用long long vector 创建数据框,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17558658/