首次尝试在Rcpp中使用R函数时出错

老虎条纹

尝试在Rcpp中编译一个函数,该函数引入了一个名为read_excel的R包。

不确定错误的含义,但也许找不到包中的功能?

cppFunction('IntegerVector readYear(CharacterVector filePath ) {

 IntegerVector Year(filePath.size());
 int n=filePath.size();

 Environment pkg = Environment::namespace_env("readxl");

 Function read_excel=pkg["read_excel"];

 for( int i =0 ; i<n; i++){


 Year[i] = read_excel(Named("path") = filePath[i],
          _["range"] = "B3:B3",
          _["col_names"] = false );
 }
 return Year;
}')

错误信息:

file391220cd2e2.cpp: In function ‘Rcpp::IntegerVector readYear(Rcpp::CharacterVector)’:
file391220cd2e2.cpp:18:22: error: invalid conversion from ‘SEXP {aka SEXPREC*}’ to ‘Rcpp::traits::storage_type<13>::type {aka int}’ [-fpermissive]
  Year[i] = read_excel(Named("path") = filePath[i],
                      ^
make: *** [file391220cd2e2.o] Error 1
g++ -std=gnu++11 -I"/opt/R/3.6.0/lib/R/include" -DNDEBUG   -I"/home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include" -I"/tmp/RtmpbaxzNs/sourceCpp-x86_64-pc-linux-gnu-1.0.2" -I/usr/local/include  -fpic  -g -O2  -c file391220cd2e2.cpp -o file391220cd2e2.o
/opt/R/3.6.0/lib/R/etc/Makeconf:176: recipe for target 'file391220cd2e2.o' failed
Error in sourceCpp(code = code, env = env, rebuild = rebuild, cacheDir = cacheDir,  : 
  Error 1 occurred building shared library.
拉尔夫·斯塔伯纳

该错误消息的装置,它不是直接可能的R函数(的返回类型转换SEXP)到的存储类型IntegerVectorint)。您可以Rcpp使用Rcpp::as<int>(...)以下方法指示这样做

Rcpp::cppFunction('IntegerVector readYear(CharacterVector filePath ) {

 int n = filePath.size();
 IntegerVector Year(n);

 Environment pkg = Environment::namespace_env("readxl");

 Function read_excel=pkg["read_excel"];

 for(int i =0; i<n; ++i){
   Year[i] = Rcpp::as<int>(read_excel(_("path") = filePath[i],
                                      _["range"] = "B3:B3",
                                      _["col_names"] = false ));
 }
 return Year;
}')

顺便说一句,我希望有充分的理由在C ++中执行此操作,因为从C ++调用R函数有其代价,因为它比同等的R函数要慢。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在R函数中使用“问题”包时出错

来自分类Dev

在R中使用clusGap函数时出错

来自分类Dev

尝试在Linq中使用包含时出错

来自分类Dev

R中使用多个if else函数时出错

来自分类Dev

尝试在C ++中使用结构时出错

来自分类Dev

在Excel中使用Vlookup函数时出错

来自分类Dev

在R中使用“ TermDocumentMatrix”和“ Dist”函数时出错

来自分类Dev

尝试从xgboost包在r中使用xgb.importance时出错

来自分类Dev

尝试在C ++中使用<filesystem>显示文件时出错

来自分类Dev

尝试在scikit-learn中使用PolynomialFeatures时出错

来自分类Dev

尝试在齿轮中使用client.latency时出错

来自分类Dev

尝试在R中使用整洁的点尝试输入任意数量的分组变量和汇总变量时出错

来自分类Dev

尝试urldownloadtofile函数时出错

来自分类Dev

在R中使用fitdist时出错-必须定义dllogis函数

来自分类Dev

尝试通过网状包在R中使用Python Gekko时出错

来自分类Dev

尝试在Google Colab中使用Tensorboard时出错

来自分类Dev

尝试在Python Jupyter中使用.difference()函数时出错

来自分类Dev

在MATLAB中使用impshowpair函数时出错

来自分类Dev

使用R中的Rcpp时出错

来自分类Dev

尝试在Java中使用Apache HttpClient进行GET时出错

来自分类Dev

尝试在Three.js中使用Mipmaping时出错

来自分类Dev

在Qt中使用QGraphicsScene函数时出错

来自分类Dev

尝试在C ++中使用结构时出错

来自分类Dev

在函数c ++中使用指针时出错

来自分类Dev

尝试在R中创建和使用随机置换测试函数时出错

来自分类Dev

尝试在 ${ForEachIn} 中使用 File 时出错?

来自分类Dev

R 尝试在 %>% 中使用 as.Date 时出错

来自分类Dev

在 R 中使用“panel.ellipse”函数时出错

来自分类Dev

在 Rcpp 函数中使用 geos

Related 相关文章

热门标签

归档