diff --git a/R/deprec-lazyeval.R b/R/deprec-lazyeval.R index e0925f539b..43c1536a3f 100644 --- a/R/deprec-lazyeval.R +++ b/R/deprec-lazyeval.R @@ -25,20 +25,12 @@ #' @keywords internal NULL -lazy_deprec <- function( - fun, - hint = TRUE, - env = caller_env(), - user_env = caller_env(2) -) { - lifecycle::deprecate_warn( +lazy_deprec <- function(fun, hint = TRUE) { + lifecycle::deprecate_stop( when = "0.7.0", what = paste0(fun, "_()"), with = paste0(fun, "()"), - details = if (hint) "See vignette('programming') for more help", - env = env, - user_env = user_env, - always = TRUE + details = if (hint) "See vignette('programming') for more help" ) } @@ -301,11 +293,10 @@ rename_.grouped_df <- function(.data, ..., .dots = list()) { #' @export #' @rdname se-deprecated rename_vars_ <- function(vars, args) { - lifecycle::deprecate_warn( + lifecycle::deprecate_stop( "0.7.0", "rename_vars_()", - "tidyselect::vars_rename()", - always = TRUE + "tidyselect::vars_rename()" ) args <- compat_lazy_dots(args, caller_env()) tidyselect::vars_rename(vars, !!!args) @@ -333,11 +324,10 @@ select_.grouped_df <- function(.data, ..., .dots = list()) { #' include/exclude. #' @export select_vars_ <- function(vars, args, include = chr(), exclude = chr()) { - lifecycle::deprecate_warn( + lifecycle::deprecate_stop( "0.7.0", "select_vars_()", - "tidyselect::vars_select()", - always = TRUE + "tidyselect::vars_select()" ) args <- compat_lazy_dots(args, caller_env()) tidyselect::vars_select(vars, !!!args, .include = include, .exclude = exclude) @@ -391,91 +381,37 @@ summarize_ <- summarise_ #' @keywords internal #' @export summarise_each <- function(tbl, funs, ...) { - summarise_each_impl(tbl, funs, enquos(...), "summarise_each") + summarise_each_impl("summarise_each") } #' @export #' @rdname summarise_each summarise_each_ <- function(tbl, funs, vars) { - summarise_each_impl(tbl, funs, vars, "summarise_each_") + summarise_each_impl("summarise_each_") } -summarise_each_impl <- function( - tbl, - funs, - vars, - name, - env = caller_env(), - user_env = caller_env(2) -) { - what <- paste0(name, "()") - - lifecycle::deprecate_warn( +summarise_each_impl <- function(name) { + lifecycle::deprecate_stop( when = "0.7.0", - what = what, - with = "across()", - always = TRUE, - env = env, - user_env = user_env + what = paste0(name, "()"), + with = "across()" ) - - if (is_empty(vars)) { - vars <- tbl_nongroup_vars(tbl) - } else { - vars <- compat_lazy_dots(vars, user_env) - vars <- tidyselect::vars_select(tbl_nongroup_vars(tbl), !!!vars) - if (length(vars) == 1 && names(vars) == as_string(vars)) { - vars <- unname(vars) - } - } - if (is_character(funs)) { - funs <- funs_(funs) - } - funs <- manip_at(tbl, vars, funs, enquo(funs), user_env, .caller = name) - summarise(tbl, !!!funs) } #' @export #' @rdname summarise_each mutate_each <- function(tbl, funs, ...) { - if (is_character(funs)) { - funs <- funs_(funs) - } - mutate_each_impl(tbl, funs, enquos(...), "mutate_each") + mutate_each_impl("mutate_each") } #' @export #' @rdname summarise_each mutate_each_ <- function(tbl, funs, vars) { - mutate_each_impl(tbl, funs, vars, "mutate_each_") + mutate_each_impl("mutate_each_") } -mutate_each_impl <- function( - tbl, - funs, - vars, - name, - env = caller_env(), - user_env = caller_env(2) -) { - what <- paste0(name, "()") - - lifecycle::deprecate_warn( +mutate_each_impl <- function(name) { + lifecycle::deprecate_stop( when = "0.7.0", - what = what, - with = "across()", - always = TRUE, - env = env, - user_env = user_env + what = paste0(name, "()"), + with = "across()" ) - - if (is_empty(vars)) { - vars <- tbl_nongroup_vars(tbl) - } else { - vars <- compat_lazy_dots(vars, user_env) - vars <- tidyselect::vars_select(tbl_nongroup_vars(tbl), !!!vars) - if (length(vars) == 1 && names(vars) == as_string(vars)) { - vars <- unname(vars) - } - } - funs <- manip_at(tbl, vars, funs, enquo(funs), user_env, .caller = name) - mutate(tbl, !!!funs) } #' @rdname summarise_each diff --git a/tests/testthat/_snaps/deprec-lazyeval.md b/tests/testthat/_snaps/deprec-lazyeval.md deleted file mode 100644 index f734b93fbb..0000000000 --- a/tests/testthat/_snaps/deprec-lazyeval.md +++ /dev/null @@ -1,58 +0,0 @@ -# mutate_each() and mutate_each_() are deprecated (#6869) - - Code - mutate_each(df, list(~ .x + 1L)) - Condition - Warning: - `mutate_each()` was deprecated in dplyr 0.7.0. - i Please use `across()` instead. - Output - # A tibble: 2 x 2 - x y - - 1 2 4 - 2 3 5 - ---- - - Code - mutate_each_(df, list(~ .x + 1L), c("x", "y")) - Condition - Warning: - `mutate_each_()` was deprecated in dplyr 0.7.0. - i Please use `across()` instead. - Output - # A tibble: 2 x 2 - x y - - 1 2 4 - 2 3 5 - -# summarise_each() and summarise_each_() are deprecated (#6869) - - Code - summarise_each(df, list(mean)) - Condition - Warning: - `summarise_each()` was deprecated in dplyr 0.7.0. - i Please use `across()` instead. - Output - # A tibble: 1 x 2 - x y - - 1 1.5 3.5 - ---- - - Code - summarise_each_(df, list(mean), c("x", "y")) - Condition - Warning: - `summarise_each_()` was deprecated in dplyr 0.7.0. - i Please use `across()` instead. - Output - # A tibble: 1 x 2 - x y - - 1 1.5 3.5 - diff --git a/tests/testthat/test-deprec-funs.R b/tests/testthat/test-deprec-funs.R index 160bac74e0..895e3a370e 100644 --- a/tests/testthat/test-deprec-funs.R +++ b/tests/testthat/test-deprec-funs.R @@ -95,25 +95,25 @@ test_that("can enfun() purrr-style lambdas", { expect_type(res[[1]], "closure") }) -test_that("funs_ works", { - withr::local_options(lifecycle_verbosity = "quiet") - - expect_equal( - funs(mean), - funs_(list(~mean)) - ) - - expect_equal( - funs_(list("mean")), - funs_(list(`environment<-`(~mean, baseenv()))), - ignore_formula_env = TRUE - ) - - expect_equal( - funs(mean(.)), - funs_(list(~ mean(.))) - ) -}) +# test_that("funs_ works", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# expect_equal( +# funs(mean), +# funs_(list(~mean)) +# ) +# +# expect_equal( +# funs_(list("mean")), +# funs_(list(`environment<-`(~mean, baseenv()))), +# ignore_formula_env = TRUE +# ) +# +# expect_equal( +# funs(mean(.)), +# funs_(list(~ mean(.))) +# ) +# }) test_that("as_fun_list() auto names chr vectors (4307)", { df <- data.frame(x = 1:10) diff --git a/tests/testthat/test-deprec-lazyeval.R b/tests/testthat/test-deprec-lazyeval.R index 33eafb2079..d59103a265 100644 --- a/tests/testthat/test-deprec-lazyeval.R +++ b/tests/testthat/test-deprec-lazyeval.R @@ -1,483 +1,483 @@ -test_that("can select negatively (#2519)", { - withr::local_options(lifecycle_verbosity = "quiet") - - expect_identical(select_(mtcars, ~ -cyl), mtcars[-2]) -}) - -test_that("select yields proper names", { - withr::local_options(lifecycle_verbosity = "quiet") - - expect_identical(names(select_(mtcars, ~ cyl:hp)), c("cyl", "disp", "hp")) -}) - -test_that("lazydots are named and arrange() doesn't fail (it assumes empty names)", { - withr::local_options(lifecycle_verbosity = "quiet") - - dots <- compat_lazy_dots(list(), env(), "cyl") - expect_identical(names(dots), "") - expect_identical(arrange_(mtcars, "cyl"), arrange(mtcars, cyl)) -}) - -test_that("mutate_each_() and summarise_each_() handle lazydots", { - withr::local_options(lifecycle_verbosity = "quiet") - - cyl_chr <- mutate_each_(mtcars, list(as.character), "cyl")$cyl - expect_identical(cyl_chr, as.character(mtcars$cyl)) - - cyl_mean <- summarise_each_(mtcars, list(mean), "cyl")$cyl - expect_equal(cyl_mean, mean(mtcars$cyl)) -}) - -test_that("mutate_each() and mutate_each_() are deprecated (#6869)", { - df <- tibble(x = 1:2, y = 3:4) - - expect_snapshot({ - mutate_each(df, list(~ .x + 1L)) - }) - expect_snapshot({ - mutate_each_(df, list(~ .x + 1L), c("x", "y")) - }) -}) - -test_that("summarise_each() and summarise_each_() are deprecated (#6869)", { - df <- tibble(x = 1:2, y = 3:4) - - expect_snapshot({ - summarise_each(df, list(mean)) - }) - expect_snapshot({ - summarise_each_(df, list(mean), c("x", "y")) - }) -}) - -test_that("select_vars_() handles lazydots", { - withr::local_options(lifecycle_verbosity = "quiet") - - expect_identical(select_vars_(letters, c("a", "b")), set_names(c("a", "b"))) - expect_identical( - select_vars_(letters, c("a", "b"), include = "c"), - set_names(c("c", "a", "b")) - ) - expect_identical( - select_vars_(letters, c("a", "b"), exclude = "b"), - set_names(c("a")) - ) -}) - -df <- tibble( - a = c(1:3, 2:3), - b = letters[c(1:4, 4L)] -) - -test_that("arrange_ works", { - withr::local_options(lifecycle_verbosity = "quiet") - - expect_equal( - arrange_(df, ~ -a), - arrange(df, -a) - ) - - expect_equal( - arrange_(df, .dots = list(quote(-a))), - arrange(df, -a) - ) - - expect_equal( - arrange_(df, .dots = list(~ -a)), - arrange(df, -a) - ) -}) - -test_that("count_() works", { - withr::local_options(lifecycle_verbosity = "quiet") - - expect_equal( - count_(df, ~b), - count(df, b) - ) - - expect_equal( - count_(df, ~b, wt = quote(a)), - count(df, b, wt = a) - ) - - wt <- 1:4 - expect_identical( - count_(df, "b", "wt"), - count(df, b, wt = wt) - ) - - expect_identical( - add_count(df, b), - add_count_(df, ~b) - ) -}) - -test_that("distinct_() works", { - withr::local_options(lifecycle_verbosity = "quiet") - - expect_equal( - distinct_(df, ~a), - distinct(df, a) - ) - - expect_equal( - distinct_(df, .dots = list(quote(a))), - distinct(df, a) - ) - - expect_equal( - distinct_(df, .dots = list(~a)), - distinct(df, a) - ) - - expect_equal( - distinct_(df |> group_by(b), ~a, .dots = NULL), - distinct(df |> group_by(b), a) - ) - - expect_equal( - distinct_(df |> group_by(b), .dots = list(quote(a))), - distinct(df |> group_by(b), a) - ) - - expect_equal( - distinct_(df |> group_by(b), .dots = list(~a)), - distinct(df |> group_by(b), a) - ) -}) - -test_that("do_() works", { - withr::local_options(lifecycle_verbosity = "quiet") - - expect_equal( - do_(df, ~ tibble(-.$a)), - do(df, tibble(-.$a)) - ) - - expect_equal( - do_(df, .dots = list(quote(dplyr::tibble(-.$a)))), - do(df, tibble(-.$a)) - ) - - expect_equal( - do_(df, .dots = list(~ dplyr::tibble(-.$a))), - do(df, tibble(-.$a)) - ) - - foo <- "foobar" - expect_identical( - do_(df, .dots = "tibble(foo)"), - do(df, tibble(foo)) - ) - - expect_equal( - do_(df |> group_by(b), ~ tibble(-.$a)), - do(df |> group_by(b), tibble(-.$a)) - ) - - expect_equal( - do_(df |> group_by(b), .dots = list(quote(dplyr::tibble(-.$a)))), - do(df |> group_by(b), tibble(-.$a)) - ) - - expect_equal( - do_(df |> group_by(b), .dots = list(~ dplyr::tibble(-.$a))), - do(df |> group_by(b), tibble(-.$a)) - ) -}) - -test_that("filter_() works", { - withr::local_options(lifecycle_verbosity = "quiet") - - expect_equal( - filter_(df, ~ a > 1), - filter(df, a > 1) - ) - - expect_equal( - filter_(df, .dots = list(quote(a > 1))), - filter(df, a > 1) - ) - - cnd <- rep(TRUE, 5) - expect_identical( - filter_(df, .dots = "cnd"), - filter(df, cnd) - ) -}) - -test_that("group_by_() works", { - withr::local_options(lifecycle_verbosity = "quiet") - - expect_equal( - group_by_(df, ~a), - group_by(df, a) - ) - - expect_equal( - group_by_(df, ~ -a), - group_by(df, -a) - ) - - expect_equal( - group_by_(df, .dots = "a"), - group_by(df, a) - ) - - expect_equal( - group_by_(df, .dots = list(quote(-a))), - group_by(df, -a) - ) - - expect_equal( - group_by_(df, .dots = list(~ -a)), - group_by(df, -a) - ) -}) - -test_that("mutate_() works", { - withr::local_options(lifecycle_verbosity = "quiet") - - expect_equal( - mutate_(df, c = ~ -a), - mutate(df, c = -a) - ) - - expect_equal( - mutate_(df, .dots = list(c = quote(-a))), - mutate(df, c = -a) - ) - - expect_equal( - mutate_(df, .dots = list(c = ~ -a)), - mutate(df, c = -a) - ) - - expect_identical( - mutate_(df, ~ -a), - mutate(df, -a) - ) - - foo <- "foobar" - expect_identical( - mutate_(df, .dots = "foo"), - mutate(df, foo) - ) -}) - -test_that("rename_() works", { - withr::local_options(lifecycle_verbosity = "quiet") - - expect_equal( - rename_(df, c = ~a), - rename(df, c = a) - ) - - expect_equal( - rename_(df, .dots = list(c = quote(a))), - rename(df, c = a) - ) - - expect_equal( - rename_(df, .dots = list(c = ~a)), - rename(df, c = a) - ) -}) - -test_that("select_() works", { - withr::local_options(lifecycle_verbosity = "quiet") - - expect_equal( - select_(df, ~a), - select(df, a) - ) - - expect_equal( - select_(df, ~ -a), - select(df, -a) - ) - - expect_equal( - select_(df, .dots = "a"), - select(df, a) - ) - - expect_equal( - select_(df, .dots = list(quote(-a))), - select(df, -a) - ) - - expect_equal( - select_(df, .dots = list(~ -a)), - select(df, -a) - ) -}) - -test_that("slice_() works", { - withr::local_options(lifecycle_verbosity = "quiet") - - expect_equal( - slice_(df, ~ 2:n()), - slice(df, 2:n()) - ) - - expect_equal( - slice_(df, .dots = list(quote(2:n()))), - slice(df, 2:n()) - ) - - expect_equal( - slice_(df, .dots = list(~ 2:n())), - slice(df, 2:n()) - ) - - pos <- 3 - expect_identical( - slice_(df, .dots = "pos:n()"), - slice(df, pos:n()) - ) -}) - -test_that("summarise_() works", { - withr::local_options(lifecycle_verbosity = "quiet") - - expect_equal( - summarise_(df, a = ~ mean(a)), - summarise(df, a = mean(a)) - ) - - expect_equal( - summarise_(df, .dots = list(a = quote(mean(a)))), - summarise(df, a = mean(a)) - ) - - expect_equal( - summarise_(df, .dots = list(a = ~ mean(a))), - summarise(df, a = mean(a)) - ) - - my_mean <- mean - expect_identical( - summarise_(df, .dots = c(a = "my_mean(a)")), - summarise(df, a = my_mean(a)) - ) - - expect_equal( - summarise_(df |> group_by(b), a = ~ mean(a)), - summarise(df |> group_by(b), a = mean(a)) - ) - - expect_equal( - summarise_(df |> group_by(b), .dots = list(a = quote(mean(a)))), - summarise(df |> group_by(b), a = mean(a)) - ) - - expect_equal( - summarise_(df |> group_by(b), .dots = list(a = ~ mean(a))), - summarise(df |> group_by(b), a = mean(a)) - ) -}) - -test_that("summarize_() works", { - withr::local_options(lifecycle_verbosity = "quiet") - - expect_equal( - summarize_(df, a = ~ mean(a)), - summarize(df, a = mean(a)) - ) - - expect_equal( - summarize_(df, .dots = list(a = quote(mean(a)))), - summarize(df, a = mean(a)) - ) - - expect_equal( - summarize_(df, .dots = list(a = ~ mean(a))), - summarize(df, a = mean(a)) - ) - - expect_equal( - summarize_(df |> group_by(b), a = ~ mean(a)), - summarize(df |> group_by(b), a = mean(a)) - ) - - expect_equal( - summarize_(df |> group_by(b), .dots = list(a = quote(mean(a)))), - summarize(df |> group_by(b), a = mean(a)) - ) - - expect_equal( - summarize_(df |> group_by(b), .dots = list(a = ~ mean(a))), - summarize(df |> group_by(b), a = mean(a)) - ) -}) - -test_that("transmute_() works", { - withr::local_options(lifecycle_verbosity = "quiet") - - expect_equal( - transmute_(df, c = ~ -a), - transmute(df, c = -a) - ) - - expect_equal( - transmute_(df, .dots = list(c = quote(-a))), - transmute(df, c = -a) - ) - - expect_equal( - transmute_(df, .dots = list(c = ~ -a)), - transmute(df, c = -a) - ) - - foo <- "foobar" - expect_identical( - transmute_(df, .dots = "foo"), - transmute(df, foo) - ) -}) - -test_that("_each() and _all() families agree", { - withr::local_options(lifecycle_verbosity = "quiet") - - df <- data.frame(x = 1:3, y = 1:3) - - expect_equal(summarise_each(df, list(mean)), summarise_all(df, mean)) - expect_equal( - summarise_each(df, list(mean), x), - summarise_at(df, vars(x), mean) - ) - expect_equal( - summarise_each(df, list(mean = mean), x), - summarise_at(df, vars(x), list(mean = mean)) - ) - expect_equal( - summarise_each(df, list(mean = mean), x:y), - summarise_at(df, vars(x:y), list(mean = mean)) - ) - expect_equal( - summarise_each(df, list(mean), x:y), - summarise_at(df, vars(x:y), mean) - ) - expect_equal( - summarise_each(df, list(mean), z = y), - summarise_at(df, vars(z = y), mean) - ) - - expect_equal(mutate_each(df, list(mean)), mutate_all(df, mean)) - expect_equal(mutate_each(df, list(mean), x), mutate_at(df, vars(x), mean)) - expect_equal( - mutate_each(df, list(mean = mean), x), - mutate_at(df, vars(x), list(mean = mean)) - ) - expect_equal( - mutate_each(df, list(mean = mean), x:y), - mutate_at(df, vars(x:y), list(mean = mean)) - ) - expect_equal(mutate_each(df, list(mean), x:y), mutate_at(df, vars(x:y), mean)) - expect_equal( - mutate_each(df, list(mean), z = y), - mutate_at(df, vars(z = y), mean) - ) -}) +# test_that("can select negatively (#2519)", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# expect_identical(select_(mtcars, ~ -cyl), mtcars[-2]) +# }) +# +# test_that("select yields proper names", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# expect_identical(names(select_(mtcars, ~ cyl:hp)), c("cyl", "disp", "hp")) +# }) +# +# test_that("lazydots are named and arrange() doesn't fail (it assumes empty names)", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# dots <- compat_lazy_dots(list(), env(), "cyl") +# expect_identical(names(dots), "") +# expect_identical(arrange_(mtcars, "cyl"), arrange(mtcars, cyl)) +# }) +# +# test_that("mutate_each_() and summarise_each_() handle lazydots", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# cyl_chr <- mutate_each_(mtcars, list(as.character), "cyl")$cyl +# expect_identical(cyl_chr, as.character(mtcars$cyl)) +# +# cyl_mean <- summarise_each_(mtcars, list(mean), "cyl")$cyl +# expect_equal(cyl_mean, mean(mtcars$cyl)) +# }) +# +# test_that("mutate_each() and mutate_each_() are deprecated (#6869)", { +# df <- tibble(x = 1:2, y = 3:4) +# +# expect_snapshot({ +# mutate_each(df, list(~ .x + 1L)) +# }) +# expect_snapshot({ +# mutate_each_(df, list(~ .x + 1L), c("x", "y")) +# }) +# }) +# +# test_that("summarise_each() and summarise_each_() are deprecated (#6869)", { +# df <- tibble(x = 1:2, y = 3:4) +# +# expect_snapshot({ +# summarise_each(df, list(mean)) +# }) +# expect_snapshot({ +# summarise_each_(df, list(mean), c("x", "y")) +# }) +# }) +# +# test_that("select_vars_() handles lazydots", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# expect_identical(select_vars_(letters, c("a", "b")), set_names(c("a", "b"))) +# expect_identical( +# select_vars_(letters, c("a", "b"), include = "c"), +# set_names(c("c", "a", "b")) +# ) +# expect_identical( +# select_vars_(letters, c("a", "b"), exclude = "b"), +# set_names(c("a")) +# ) +# }) +# +# df <- tibble( +# a = c(1:3, 2:3), +# b = letters[c(1:4, 4L)] +# ) +# +# test_that("arrange_ works", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# expect_equal( +# arrange_(df, ~ -a), +# arrange(df, -a) +# ) +# +# expect_equal( +# arrange_(df, .dots = list(quote(-a))), +# arrange(df, -a) +# ) +# +# expect_equal( +# arrange_(df, .dots = list(~ -a)), +# arrange(df, -a) +# ) +# }) +# +# test_that("count_() works", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# expect_equal( +# count_(df, ~b), +# count(df, b) +# ) +# +# expect_equal( +# count_(df, ~b, wt = quote(a)), +# count(df, b, wt = a) +# ) +# +# wt <- 1:4 +# expect_identical( +# count_(df, "b", "wt"), +# count(df, b, wt = wt) +# ) +# +# expect_identical( +# add_count(df, b), +# add_count_(df, ~b) +# ) +# }) +# +# test_that("distinct_() works", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# expect_equal( +# distinct_(df, ~a), +# distinct(df, a) +# ) +# +# expect_equal( +# distinct_(df, .dots = list(quote(a))), +# distinct(df, a) +# ) +# +# expect_equal( +# distinct_(df, .dots = list(~a)), +# distinct(df, a) +# ) +# +# expect_equal( +# distinct_(df |> group_by(b), ~a, .dots = NULL), +# distinct(df |> group_by(b), a) +# ) +# +# expect_equal( +# distinct_(df |> group_by(b), .dots = list(quote(a))), +# distinct(df |> group_by(b), a) +# ) +# +# expect_equal( +# distinct_(df |> group_by(b), .dots = list(~a)), +# distinct(df |> group_by(b), a) +# ) +# }) +# +# test_that("do_() works", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# expect_equal( +# do_(df, ~ tibble(-.$a)), +# do(df, tibble(-.$a)) +# ) +# +# expect_equal( +# do_(df, .dots = list(quote(dplyr::tibble(-.$a)))), +# do(df, tibble(-.$a)) +# ) +# +# expect_equal( +# do_(df, .dots = list(~ dplyr::tibble(-.$a))), +# do(df, tibble(-.$a)) +# ) +# +# foo <- "foobar" +# expect_identical( +# do_(df, .dots = "tibble(foo)"), +# do(df, tibble(foo)) +# ) +# +# expect_equal( +# do_(df |> group_by(b), ~ tibble(-.$a)), +# do(df |> group_by(b), tibble(-.$a)) +# ) +# +# expect_equal( +# do_(df |> group_by(b), .dots = list(quote(dplyr::tibble(-.$a)))), +# do(df |> group_by(b), tibble(-.$a)) +# ) +# +# expect_equal( +# do_(df |> group_by(b), .dots = list(~ dplyr::tibble(-.$a))), +# do(df |> group_by(b), tibble(-.$a)) +# ) +# }) +# +# test_that("filter_() works", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# expect_equal( +# filter_(df, ~ a > 1), +# filter(df, a > 1) +# ) +# +# expect_equal( +# filter_(df, .dots = list(quote(a > 1))), +# filter(df, a > 1) +# ) +# +# cnd <- rep(TRUE, 5) +# expect_identical( +# filter_(df, .dots = "cnd"), +# filter(df, cnd) +# ) +# }) +# +# test_that("group_by_() works", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# expect_equal( +# group_by_(df, ~a), +# group_by(df, a) +# ) +# +# expect_equal( +# group_by_(df, ~ -a), +# group_by(df, -a) +# ) +# +# expect_equal( +# group_by_(df, .dots = "a"), +# group_by(df, a) +# ) +# +# expect_equal( +# group_by_(df, .dots = list(quote(-a))), +# group_by(df, -a) +# ) +# +# expect_equal( +# group_by_(df, .dots = list(~ -a)), +# group_by(df, -a) +# ) +# }) +# +# test_that("mutate_() works", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# expect_equal( +# mutate_(df, c = ~ -a), +# mutate(df, c = -a) +# ) +# +# expect_equal( +# mutate_(df, .dots = list(c = quote(-a))), +# mutate(df, c = -a) +# ) +# +# expect_equal( +# mutate_(df, .dots = list(c = ~ -a)), +# mutate(df, c = -a) +# ) +# +# expect_identical( +# mutate_(df, ~ -a), +# mutate(df, -a) +# ) +# +# foo <- "foobar" +# expect_identical( +# mutate_(df, .dots = "foo"), +# mutate(df, foo) +# ) +# }) +# +# test_that("rename_() works", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# expect_equal( +# rename_(df, c = ~a), +# rename(df, c = a) +# ) +# +# expect_equal( +# rename_(df, .dots = list(c = quote(a))), +# rename(df, c = a) +# ) +# +# expect_equal( +# rename_(df, .dots = list(c = ~a)), +# rename(df, c = a) +# ) +# }) +# +# test_that("select_() works", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# expect_equal( +# select_(df, ~a), +# select(df, a) +# ) +# +# expect_equal( +# select_(df, ~ -a), +# select(df, -a) +# ) +# +# expect_equal( +# select_(df, .dots = "a"), +# select(df, a) +# ) +# +# expect_equal( +# select_(df, .dots = list(quote(-a))), +# select(df, -a) +# ) +# +# expect_equal( +# select_(df, .dots = list(~ -a)), +# select(df, -a) +# ) +# }) +# +# test_that("slice_() works", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# expect_equal( +# slice_(df, ~ 2:n()), +# slice(df, 2:n()) +# ) +# +# expect_equal( +# slice_(df, .dots = list(quote(2:n()))), +# slice(df, 2:n()) +# ) +# +# expect_equal( +# slice_(df, .dots = list(~ 2:n())), +# slice(df, 2:n()) +# ) +# +# pos <- 3 +# expect_identical( +# slice_(df, .dots = "pos:n()"), +# slice(df, pos:n()) +# ) +# }) +# +# test_that("summarise_() works", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# expect_equal( +# summarise_(df, a = ~ mean(a)), +# summarise(df, a = mean(a)) +# ) +# +# expect_equal( +# summarise_(df, .dots = list(a = quote(mean(a)))), +# summarise(df, a = mean(a)) +# ) +# +# expect_equal( +# summarise_(df, .dots = list(a = ~ mean(a))), +# summarise(df, a = mean(a)) +# ) +# +# my_mean <- mean +# expect_identical( +# summarise_(df, .dots = c(a = "my_mean(a)")), +# summarise(df, a = my_mean(a)) +# ) +# +# expect_equal( +# summarise_(df |> group_by(b), a = ~ mean(a)), +# summarise(df |> group_by(b), a = mean(a)) +# ) +# +# expect_equal( +# summarise_(df |> group_by(b), .dots = list(a = quote(mean(a)))), +# summarise(df |> group_by(b), a = mean(a)) +# ) +# +# expect_equal( +# summarise_(df |> group_by(b), .dots = list(a = ~ mean(a))), +# summarise(df |> group_by(b), a = mean(a)) +# ) +# }) +# +# test_that("summarize_() works", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# expect_equal( +# summarize_(df, a = ~ mean(a)), +# summarize(df, a = mean(a)) +# ) +# +# expect_equal( +# summarize_(df, .dots = list(a = quote(mean(a)))), +# summarize(df, a = mean(a)) +# ) +# +# expect_equal( +# summarize_(df, .dots = list(a = ~ mean(a))), +# summarize(df, a = mean(a)) +# ) +# +# expect_equal( +# summarize_(df |> group_by(b), a = ~ mean(a)), +# summarize(df |> group_by(b), a = mean(a)) +# ) +# +# expect_equal( +# summarize_(df |> group_by(b), .dots = list(a = quote(mean(a)))), +# summarize(df |> group_by(b), a = mean(a)) +# ) +# +# expect_equal( +# summarize_(df |> group_by(b), .dots = list(a = ~ mean(a))), +# summarize(df |> group_by(b), a = mean(a)) +# ) +# }) +# +# test_that("transmute_() works", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# expect_equal( +# transmute_(df, c = ~ -a), +# transmute(df, c = -a) +# ) +# +# expect_equal( +# transmute_(df, .dots = list(c = quote(-a))), +# transmute(df, c = -a) +# ) +# +# expect_equal( +# transmute_(df, .dots = list(c = ~ -a)), +# transmute(df, c = -a) +# ) +# +# foo <- "foobar" +# expect_identical( +# transmute_(df, .dots = "foo"), +# transmute(df, foo) +# ) +# }) +# +# test_that("_each() and _all() families agree", { +# withr::local_options(lifecycle_verbosity = "quiet") +# +# df <- data.frame(x = 1:3, y = 1:3) +# +# expect_equal(summarise_each(df, list(mean)), summarise_all(df, mean)) +# expect_equal( +# summarise_each(df, list(mean), x), +# summarise_at(df, vars(x), mean) +# ) +# expect_equal( +# summarise_each(df, list(mean = mean), x), +# summarise_at(df, vars(x), list(mean = mean)) +# ) +# expect_equal( +# summarise_each(df, list(mean = mean), x:y), +# summarise_at(df, vars(x:y), list(mean = mean)) +# ) +# expect_equal( +# summarise_each(df, list(mean), x:y), +# summarise_at(df, vars(x:y), mean) +# ) +# expect_equal( +# summarise_each(df, list(mean), z = y), +# summarise_at(df, vars(z = y), mean) +# ) +# +# expect_equal(mutate_each(df, list(mean)), mutate_all(df, mean)) +# expect_equal(mutate_each(df, list(mean), x), mutate_at(df, vars(x), mean)) +# expect_equal( +# mutate_each(df, list(mean = mean), x), +# mutate_at(df, vars(x), list(mean = mean)) +# ) +# expect_equal( +# mutate_each(df, list(mean = mean), x:y), +# mutate_at(df, vars(x:y), list(mean = mean)) +# ) +# expect_equal(mutate_each(df, list(mean), x:y), mutate_at(df, vars(x:y), mean)) +# expect_equal( +# mutate_each(df, list(mean), z = y), +# mutate_at(df, vars(z = y), mean) +# ) +# })