forked from tidyverse/dplyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* with_hybrid(), without_hybrid(), eval_dots(), expectations, and machinery - use f_capture() - special-case enclosing list() call * add various hybrid tests - test n() and n_distinct() - improve %in% tests - test min() and max() - test first(), last(), and nth() - improve nth() tests - test lead() and lag() - test mean(), var(), sd() and sum() - test row_number(), ntile(), min_rank(), percent_rank(), dense_rank(), and cume_dist() - test complex numbers - test call matching - constfold-related test - test nesting of hybrid handlers - add failing test * ntile() returns integer * improve nth() use typeof() instead of class() keep treating n as numeric, it is a numeric anyway after trunc() * add expect_error() * skip failing tests * failing on Windows * add common use case for n() * NEWS
- Loading branch information
Showing
10 changed files
with
838 additions
and
24 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,7 @@ Collate: | |
'group-indices.R' | ||
'group-size.r' | ||
'grouped-df.r' | ||
'hybrid.R' | ||
'id.r' | ||
'if_else.R' | ||
'inline.r' | ||
|
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,50 @@ | ||
verify_hybrid <- function(x) { | ||
stop("Not in hybrid evaluation", call. = FALSE) | ||
} | ||
|
||
verify_not_hybrid <- function(x) { | ||
x | ||
} | ||
|
||
with_hybrid <- function(expr, ...) { | ||
with_hybrid_(lazyeval::f_capture(expr), ...) | ||
} | ||
|
||
with_hybrid_ <- function(expr, ...) { | ||
stopifnot(any(class(expr) == "formula")) | ||
expr[[2]] <- prepend_call(expr[[2]], "verify_hybrid") | ||
data <- data_frame(...) | ||
summarise_(data, out = expr)["out"][[1]] | ||
} | ||
|
||
without_hybrid <- function(expr, ...) { | ||
.dots <- lazyeval::lazy_dots(out = expr)[[1]] | ||
without_hybrid_(lazyeval::f_new(.dots$expr, env = .dots$env), ...) | ||
} | ||
|
||
without_hybrid_ <- function(expr, ...) { | ||
stopifnot(any(class(expr) == "formula")) | ||
expr[[2]] <- prepend_call(expr[[2]], "verify_not_hybrid") | ||
data <- data_frame(...) | ||
summarise_(data, out = expr)["out"][[1]] | ||
} | ||
|
||
eval_dots <- function(expr, ...) { | ||
eval_dots_(lazyeval::f_capture(expr), ...) | ||
} | ||
|
||
eval_dots_ <- function(expr, ...) { | ||
data <- data_frame(...) | ||
eval(expr[[2]], data, enclos = environment(expr)) | ||
} | ||
|
||
# some(func()) -> name(some(func())) | ||
# list(some(func())) -> list(name(some(func()))) | ||
prepend_call <- function(expr, name) { | ||
if (is.call(expr) && expr[[1]] == quote(list)) { | ||
stopifnot(length(expr) == 2L) | ||
call("list", call(name, expr[[2]])) | ||
} else { | ||
call(name, expr) | ||
} | ||
} |
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
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,92 @@ | ||
#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 VerifyHybrid : public Result { | ||
public: | ||
VerifyHybrid(SEXP x_) : x(x_) {} | ||
|
||
public: | ||
SEXP process(const RowwiseDataFrame&) { | ||
return x; | ||
} | ||
|
||
SEXP process(const GroupedDataFrame&) { | ||
return x; | ||
} | ||
|
||
SEXP process(const FullDataFrame&) { | ||
return x; | ||
} | ||
|
||
SEXP process(const SlicingIndex&) { | ||
return x; | ||
} | ||
|
||
private: | ||
RObject x; | ||
}; | ||
|
||
Result* verify_hybrid_prototype(SEXP call, const ILazySubsets& subsets, int nargs) { | ||
// if not exactly one arg, let R handle it | ||
if (nargs != 1) | ||
return 0; | ||
|
||
// if it isn't a constant, let R handle it | ||
SEXP arg = CADR(call); | ||
if (TYPEOF(arg) == SYMSXP || TYPEOF(arg) == LANGSXP) | ||
return 0; | ||
|
||
return new VerifyHybrid(arg); | ||
} | ||
|
||
class VerifyNotHybrid : public Result { | ||
public: | ||
VerifyNotHybrid(SEXP x_) : x(x_) {} | ||
|
||
public: | ||
SEXP process(const RowwiseDataFrame&) { | ||
stop("In hybrid evaluation"); | ||
} | ||
|
||
SEXP process(const GroupedDataFrame&) { | ||
stop("In hybrid evaluation"); | ||
} | ||
|
||
SEXP process(const FullDataFrame&) { | ||
stop("In hybrid evaluation"); | ||
} | ||
|
||
SEXP process(const SlicingIndex&) { | ||
stop("In hybrid evaluation"); | ||
} | ||
|
||
private: | ||
RObject x; | ||
}; | ||
|
||
Result* verify_not_hybrid_prototype(SEXP call, const ILazySubsets& subsets, int nargs) { | ||
// if not exactly one arg, let R handle it | ||
if (nargs != 1) | ||
return 0; | ||
|
||
// if it isn't a constant, let R handle it | ||
SEXP arg = CADR(call); | ||
if (TYPEOF(arg) == SYMSXP || TYPEOF(arg) == LANGSXP) | ||
return 0; | ||
|
||
return new VerifyNotHybrid(arg); | ||
} | ||
|
||
void install_debug_handlers(HybridHandlerMap& handlers) { | ||
handlers[ Rf_install("verify_hybrid") ] = verify_hybrid_prototype; | ||
handlers[ Rf_install("verify_not_hybrid") ] = verify_not_hybrid_prototype; | ||
} |
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,41 @@ | ||
check_hybrid_result <- function(expr, ..., expected, test_eval = TRUE) { | ||
check_hybrid_result_(lazyeval::f_capture(expr), ..., expected = expected, test_eval = test_eval) | ||
} | ||
|
||
check_hybrid_result_ <- function(expr, ..., expected, test_eval) { | ||
expect_error(expect_identical(with_hybrid_(expr, ...), expected), NA) | ||
if (test_eval) { | ||
expect_identical(eval_dots_(expr, ...), expected) | ||
} | ||
} | ||
|
||
check_not_hybrid_result <- function(expr, ..., expected, test_eval = TRUE) { | ||
check_not_hybrid_result_(lazyeval::f_capture(expr), ..., expected = expected, test_eval = test_eval) | ||
} | ||
|
||
check_not_hybrid_result_ <- function(expr, ..., expected, test_eval) { | ||
expect_error(expect_identical(without_hybrid_(expr, ...), expected), NA) | ||
if (test_eval) { | ||
expect_identical(eval_dots_(expr, ...), expected) | ||
} | ||
} | ||
|
||
expect_hybrid_error <- function(expr, ..., error) { | ||
expect_hybrid_error_(lazyeval::f_capture(expr), ..., error = error) | ||
} | ||
|
||
expect_hybrid_error_ <- function(expr, ..., error) { | ||
expect_error( | ||
with_hybrid_(expr, ...), | ||
error) | ||
} | ||
|
||
expect_not_hybrid_error <- function(expr, ..., error) { | ||
expect_not_hybrid_error_(lazyeval::f_capture(expr), ..., error = error) | ||
} | ||
|
||
expect_not_hybrid_error_ <- function(expr, ..., error) { | ||
expect_error( | ||
without_hybrid_(expr, ...), | ||
error) | ||
} |
Oops, something went wrong.