-3

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

MSW Data
  • 441
  • 3
  • 8
  • Do you have [plogr](https://cran.r-project.org/package=plogr) installed? – Ralf Stubner Jun 13 '18 at 04:58
  • Yes - I have installed plogr, bindrcpp, dplyr, Rcpp. – MSW Data Jun 13 '18 at 05:03
  • 2
    Try adding `// [[Rcpp::depends(plogr)]]` – Ralf Stubner Jun 13 '18 at 05:06
  • I had to reinstall the newer version of plogr, bind_rcpp and dply from github. The codes complies fine now but does complain that dplyr::DataFrameVisitors has no member named "subset". It seems like subset has been deprecated but I am not aware of the newer method as yet. – MSW Data Jun 13 '18 at 06:47

1 Answers1

1

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

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

F. Privé
  • 11,423
  • 2
  • 27
  • 78
  • Yes - thanks guys. I am not getting any compilation error anymore. – MSW Data Jun 13 '18 at 06:52
  • Looking at https://github.com/tidyverse/dplyr/blob/master/inst/include/dplyr/DataFrameVisitors.h - you will notice that subset is not a member function anymore for Class DataFrameVisitor – MSW Data Jun 13 '18 at 06:53
  • 2
    From what I understand of Stack Overflow, you must have one question for one error. You can't ask to solve all your possible issues at once. Otherwise, it would a code review site and won't be searchable for specific issues. – F. Privé Jun 13 '18 at 06:59
  • @MSWData This probably means that the original solution no longer works as well. Since you do not have enough rep, I have added a comment there. – Ralf Stubner Jun 13 '18 at 08:10
  • @RalfStubner Thanks for your help and patience guys - really appreciate. – MSW Data Jun 14 '18 at 00:53