Ordering dataframe using Rcpp & Dplyr

匿名 (未验证) 提交于 2019-12-03 00:46:02

问题:

first post on this forum so feel free to go easy :-)

I am trying to sort a dataframe using Rcpp/dplyr. Based on an earlier post from Romain - the idea is to use the OrderVisitor class as explained in this post.

order a dataframe by column in Rcpp

My problem is I cannot compile the MyFunc code below as defined in above post.

C++:

enter code here  #include <Rcpp.h> #include <dplyr.h>  using namespace Rcpp; using namespace dplyr;  // [[Rcpp::export]] // [[Rcpp::depends(dplyr)]]   DataFrame myFunc(DataFrame data, CharacterVector names) {     OrderVisitors o(data, names ) ;     IntegerVector index = o.apply() ;      DataFrameVisitors visitors( data ) ;     DataFrame res = visitors.subset(index, "data.frame" ) ;      return res;   } 

RStudio Compile message:

sessioninfo::session_info() ― Session info ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― setting value
version R version 3.4.1 (2017-06-30) os Windows 7 x64 SP 1
system x86_64, mingw32
ui RStudio
language (EN)
collate English_United States.1252
tz Australia/Sydney
date 2018-06-13

― Packages ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― package * version date source
clisymbols 1.2.0 2017-05-21 CRAN (R 3.4.4) sessioninfo 1.0.0 2017-06-21 CRAN (R 3.4.4) withr 2.1.2 2018-03-15 CRAN (R 3.4.4) yaml 2.1.14 2016-11-12 CRAN (R 3.4.1)

Rcpp::sourceCpp('C:/temp/test.cpp') c:/RBuildTools/3.4/mingw_64/bin/g++ -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I"C:/PROGRA~1/R/R-34~1.1/library/Rcpp/include" -I"C:/PROGRA~1/R/R-34~1.1/library/dplyr/include" -I"C:/PROGRA~1/R/R-34~1.1/library/BH/include" -I"C:/temp" -I"d:/Compiler/gcc-4.9.3/local330/include" -O2 -Wall -mtune=core2 -c test.cpp -o test.o In file included from C:/PROGRA~1/R/R-34~1.1/library/dplyr/include/dplyr.h:4:0, from test.cpp:2: C:/PROGRA~1/R/R-34~1.1/library/dplyr/include/dplyr/main.h:11:19: fatal error: plogr.h: No such file or directory #include ^ compilation terminated. make: *** [test.o] Error 1 Warning message: running command 'make -f "C:/PROGRA~1/R/R-34~1.1/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-34~1.1/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="sourceCpp_2.dll" WIN=64 TCLBIN=64 OBJECTS="test.o"' had status 2 Error in Rcpp::sourceCpp("C:/temp/test.cpp") : Error 1 occurred building shared library.

so what I want to know is :

  1. Any idea how to compile above code properly? Any issues with plogr?

  2. Any other efficient way of achieving the same result using Rcpp?

Thanks.

MSW

回答1:

As Ralf said, you may need to add other dependencies.

In this case, you need all these: // [[Rcpp::depends(dplyr, plogr, bindrcpp)]].



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!