Skip to content

Commit

Permalink
Handle quosured symbols in remaining windowed handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Jun 16, 2017
1 parent aa153ec commit c35bf3a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/hybrid_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ Result* ntile_prototype(SEXP call, const ILazySubsets& subsets, int nargs) {
if (nargs != 2) return 0;

// handle 2nd arg
SEXP ntiles = CADDR(call);
SEXP ntiles = maybe_rhs(CADDR(call));
if (TYPEOF(ntiles) != INTSXP && TYPEOF(ntiles) != REALSXP) return 0;
int number_tiles = as<int>(ntiles);
if (number_tiles == NA_INTEGER) return 0;

RObject data(CADR(call));
RObject data(maybe_rhs(CADR(call)));
bool ascending = true;
if (TYPEOF(data) == LANGSXP && CAR(data) == Rf_install("desc")) {
data = CADR(data);
Expand Down
20 changes: 18 additions & 2 deletions tests/testthat/test-mutate-windowed.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,27 @@ test_that("dim attribute is stripped from grouped mutate (#1918)", {
expect_null(dim(df_rowwise$b))
})

test_that("min_rank() is hybrided even with quosures", {
min_rank <- bad_hybrid_handler
test_that("window handlers handle quosured symbols", {
ntile <- min_rank <- percent_rank <- dense_rank <- cume_dist <- bad_hybrid_handler

expect_identical(
pull(mutate(mtcars, ntile(!! quo(disp), 2))),
dplyr::ntile(mtcars$disp, 2)
)
expect_identical(
pull(mutate(mtcars, min_rank(!! quo(cyl)))),
dplyr::min_rank(mtcars$cyl)
)
expect_identical(
pull(mutate(mtcars, percent_rank(!! quo(cyl)))),
dplyr::percent_rank(mtcars$cyl)
)
expect_identical(
pull(mutate(mtcars, dense_rank(!! quo(cyl)))),
dplyr::dense_rank(mtcars$cyl)
)
expect_identical(
pull(mutate(mtcars, cume_dist(!! quo(cyl)))),
dplyr::cume_dist(mtcars$cyl)
)
})

0 comments on commit c35bf3a

Please sign in to comment.