-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
give hybrid meaning to group_indices(), as in #1185
```r > df <- data_frame(v1 = c(NA, NA, 2, 2, 3), v2 = c(NA, NA, 3,3, 4)) %>% group_by(v1) > df %>% mutate( g = group_indices() ) # A tibble: 5 x 3 # Groups: v1 [3] v1 v2 g <dbl> <dbl> <int> 1 NA NA 3 2 NA NA 3 3 2. 3. 1 4 2. 3. 1 5 3. 4. 2 ```
- Loading branch information
1 parent
bfc9b28
commit 4d76bb3
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "pch.h" | ||
#include <dplyr/main.h> | ||
|
||
#include <dplyr/HybridHandlerMap.h> | ||
|
||
#include <dplyr/Result/ILazySubsets.h> | ||
|
||
#include <dplyr/Result/Result.h> | ||
|
||
using namespace Rcpp; | ||
using namespace dplyr; | ||
|
||
|
||
class GroupHybrid : public Result { | ||
public: | ||
SEXP process(const RowwiseDataFrame&) { | ||
Rprintf( "GroupHybrid::RowwiseDataFrame()\n" ) ; | ||
return R_NilValue ; | ||
} | ||
|
||
SEXP process(const GroupedDataFrame&) { | ||
Rprintf( "GroupHybrid::GroupedDataFrame()\n" ) ; | ||
return R_NilValue ; | ||
} | ||
|
||
SEXP process(const FullDataFrame&) { | ||
Rprintf( "GroupHybrid::FullDataFrame()\n" ) ; | ||
return R_NilValue ; | ||
} | ||
|
||
SEXP process(const SlicingIndex& i) { | ||
return IntegerVector(i.size(), i.group() + 1); | ||
} | ||
}; | ||
|
||
Result* group_prototype(SEXP call, const ILazySubsets&, int nargs) { | ||
if (nargs != 0) | ||
return 0; | ||
|
||
return new GroupHybrid(); | ||
} | ||
|
||
void install_group_handlers(HybridHandlerMap& handlers) { | ||
Environment ns_dplyr = Environment::namespace_env("dplyr"); | ||
handlers[ Rf_install("group_indices") ] = HybridHandler(group_prototype, ns_dplyr["group_indices"]); | ||
} |