Skip to content

Commit

Permalink
Handle quosured symbols in nth handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Jun 16, 2017
1 parent 5ba12b6 commit fd6be86
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/hybrid_nth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ Result* nth_prototype(SEXP call, const ILazySubsets& subsets, int nargs) {
if (tag != R_NilValue && tag != Rf_install("x")) {
return 0;
}
SEXP data = CADR(call);
SEXP data = maybe_rhs(CADR(call));
if (TYPEOF(data) != SYMSXP)
return 0;

Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-nth-value.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,20 @@ test_that("firsts uses default value for 0 length augmented vectors", {
expect_equal(first(dt[0]), dt[NA])
expect_equal(first(tm[0]), tm[NA])
})

test_that("handle quosured symbols in nth handlers", {
first <- last <- nth <- bad_hybrid_handler

expect_identical(
pull(summarise(mtcars, first(!! quo(cyl)))),
dplyr::first(mtcars$cyl)
)
expect_identical(
pull(summarise(mtcars, last(!! quo(cyl)))),
dplyr::last(mtcars$cyl)
)
expect_identical(
pull(summarise(mtcars, nth(!! quo(cyl), 2))),
dplyr::nth(mtcars$cyl, 2)
)
})

0 comments on commit fd6be86

Please sign in to comment.