From c7ebfd20eedda808827518cb91e5c5332e05f839 Mon Sep 17 00:00:00 2001 From: Lionel Henry Date: Tue, 20 Sep 2022 17:47:04 +0200 Subject: [PATCH] Use magrittr pipe --- tests/testthat/_snaps/conditions.md | 128 ++++++++++++++++------------ tests/testthat/test-conditions.R | 44 +++++----- 2 files changed, 94 insertions(+), 78 deletions(-) diff --git a/tests/testthat/_snaps/conditions.md b/tests/testthat/_snaps/conditions.md index 1592b78335..54a69565e3 100644 --- a/tests/testthat/_snaps/conditions.md +++ b/tests/testthat/_snaps/conditions.md @@ -230,7 +230,7 @@ Code # Ungrouped - invisible(mutate(df, x = f())) + df %>% mutate(x = f()) %>% invisible() Condition Warning: There was 1 warning in a `mutate()` step. @@ -249,15 +249,16 @@ --- Backtrace: x - 1. +-dplyr::mutate(df, x = f()) - 2. \-dplyr:::mutate.data.frame(df, x = f()) + 1. +-df %>% mutate(x = f()) %>% invisible() + 2. +-dplyr::mutate(., x = f()) + 3. \-dplyr:::mutate.data.frame(., x = f()) --- Code # Grouped - invisible(mutate(group_by(df, id), x = f())) + df %>% group_by(id) %>% mutate(x = f()) %>% invisible() Condition Warning: There were 2 warnings in a `mutate()` step. @@ -278,8 +279,9 @@ --- Backtrace: x - 1. +-dplyr::mutate(group_by(df, id), x = f()) - 2. \-dplyr:::mutate.data.frame(group_by(df, id), x = f()) + 1. +-df %>% group_by(id) %>% mutate(x = f()) %>% invisible() + 2. +-dplyr::mutate(., x = f()) + 3. \-dplyr:::mutate.data.frame(., x = f()) [[2]] @@ -290,15 +292,16 @@ --- Backtrace: x - 1. +-dplyr::mutate(group_by(df, id), x = f()) - 2. \-dplyr:::mutate.data.frame(group_by(df, id), x = f()) + 1. +-df %>% group_by(id) %>% mutate(x = f()) %>% invisible() + 2. +-dplyr::mutate(., x = f()) + 3. \-dplyr:::mutate.data.frame(., x = f()) --- Code # Rowwise - invisible(mutate(rowwise(df), x = f())) + df %>% rowwise() %>% mutate(x = f()) %>% invisible() Condition Warning: There were 2 warnings in a `mutate()` step. @@ -319,8 +322,9 @@ --- Backtrace: x - 1. +-dplyr::mutate(rowwise(df), x = f()) - 2. \-dplyr:::mutate.data.frame(rowwise(df), x = f()) + 1. +-df %>% rowwise() %>% mutate(x = f()) %>% invisible() + 2. +-dplyr::mutate(., x = f()) + 3. \-dplyr:::mutate.data.frame(., x = f()) [[2]] @@ -331,16 +335,17 @@ --- Backtrace: x - 1. +-dplyr::mutate(rowwise(df), x = f()) - 2. \-dplyr:::mutate.data.frame(rowwise(df), x = f()) + 1. +-df %>% rowwise() %>% mutate(x = f()) %>% invisible() + 2. +-dplyr::mutate(., x = f()) + 3. \-dplyr:::mutate.data.frame(., x = f()) --- Code # Multiple type of warnings within multiple verbs - invisible(mutate(group_by(mutate(rowwise(group_by(df, g = f():n())), x = f()), - id), x = f())) + df %>% group_by(g = f():n()) %>% rowwise() %>% mutate(x = f()) %>% group_by(id) %>% + mutate(x = f()) %>% invisible() Condition Warning: There was 1 warning in a `group_by()` step. @@ -373,12 +378,13 @@ --- Backtrace: x - 1. +-dplyr::mutate(...) - 2. +-dplyr::group_by(...) - 3. +-dplyr::mutate(rowwise(group_by(df, g = f():n())), x = f()) - 4. +-dplyr::rowwise(group_by(df, g = f():n())) - 5. +-dplyr::group_by(df, g = f():n()) - 6. \-dplyr:::group_by.data.frame(df, g = f():n()) + 1. +-... %>% invisible() + 2. +-dplyr::mutate(., x = f()) + 3. +-dplyr::group_by(., id) + 4. +-dplyr::mutate(., x = f()) + 5. +-dplyr::rowwise(.) + 6. +-dplyr::group_by(., g = f():n()) + 7. \-dplyr:::group_by.data.frame(., g = f():n()) [[2]] @@ -389,10 +395,11 @@ --- Backtrace: x - 1. +-dplyr::mutate(...) - 2. +-dplyr::group_by(...) - 3. +-dplyr::mutate(rowwise(group_by(df, g = f():n())), x = f()) - 4. \-dplyr:::mutate.data.frame(...) + 1. +-... %>% invisible() + 2. +-dplyr::mutate(., x = f()) + 3. +-dplyr::group_by(., id) + 4. +-dplyr::mutate(., x = f()) + 5. \-dplyr:::mutate.data.frame(., x = f()) [[3]] @@ -403,10 +410,11 @@ --- Backtrace: x - 1. +-dplyr::mutate(...) - 2. +-dplyr::group_by(...) - 3. +-dplyr::mutate(rowwise(group_by(df, g = f():n())), x = f()) - 4. \-dplyr:::mutate.data.frame(...) + 1. +-... %>% invisible() + 2. +-dplyr::mutate(., x = f()) + 3. +-dplyr::group_by(., id) + 4. +-dplyr::mutate(., x = f()) + 5. \-dplyr:::mutate.data.frame(., x = f()) [[4]] @@ -417,8 +425,9 @@ --- Backtrace: x - 1. +-dplyr::mutate(...) - 2. \-dplyr:::mutate.data.frame(...) + 1. +-... %>% invisible() + 2. +-dplyr::mutate(., x = f()) + 3. \-dplyr:::mutate.data.frame(., x = f()) [[5]] @@ -429,15 +438,16 @@ --- Backtrace: x - 1. +-dplyr::mutate(...) - 2. \-dplyr:::mutate.data.frame(...) + 1. +-... %>% invisible() + 2. +-dplyr::mutate(., x = f()) + 3. \-dplyr:::mutate.data.frame(., x = f()) --- Code # Truncated (1 more) - mutate(rowwise(df), x = f()) + df %>% rowwise() %>% mutate(x = f()) Condition Warning: There were 2 warnings in a `mutate()` step. @@ -465,8 +475,9 @@ --- Backtrace: x - 1. +-dplyr::mutate(rowwise(df), x = f()) - 2. \-dplyr:::mutate.data.frame(rowwise(df), x = f()) + 1. +-df %>% rowwise() %>% mutate(x = f()) + 2. +-dplyr::mutate(., x = f()) + 3. \-dplyr:::mutate.data.frame(., x = f()) Message ... with 1 more warning. @@ -477,7 +488,7 @@ Code # Truncated (several more) df <- tibble(id = 1:5) - mutate(rowwise(df), x = f()) + df %>% rowwise() %>% mutate(x = f()) Condition Warning: There were 5 warnings in a `mutate()` step. @@ -508,8 +519,9 @@ --- Backtrace: x - 1. +-dplyr::mutate(rowwise(df), x = f()) - 2. \-dplyr:::mutate.data.frame(rowwise(df), x = f()) + 1. +-df %>% rowwise() %>% mutate(x = f()) + 2. +-dplyr::mutate(., x = f()) + 3. \-dplyr:::mutate.data.frame(., x = f()) Message ... with 4 more warnings. @@ -552,11 +564,12 @@ --- Backtrace: x - 1. \-dplyr (local) foo() - 2. \-dplyr (local) bar() - 3. +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE)) - 4. +-dplyr::group_by(df, x = f(1):n()) - 5. \-dplyr:::group_by.data.frame(df, x = f(1):n()) + 1. +-dplyr (local) foo() + 2. | \-dplyr (local) bar() + 3. | \-df %>% group_by(x = f(1):n()) %>% mutate(x = f(1, base = FALSE)) + 4. +-dplyr::mutate(., x = f(1, base = FALSE)) + 5. +-dplyr::group_by(., x = f(1):n()) + 6. \-dplyr:::group_by.data.frame(., x = f(1):n()) [[2]] @@ -567,10 +580,11 @@ --- Backtrace: x - 1. \-dplyr (local) foo() - 2. \-dplyr (local) bar() - 3. +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE)) - 4. \-dplyr:::mutate.data.frame(...) + 1. +-dplyr (local) foo() + 2. | \-dplyr (local) bar() + 3. | \-df %>% group_by(x = f(1):n()) %>% mutate(x = f(1, base = FALSE)) + 4. +-dplyr::mutate(., x = f(1, base = FALSE)) + 5. \-dplyr:::mutate.data.frame(., x = f(1, base = FALSE)) [[3]] @@ -581,10 +595,11 @@ --- Backtrace: x - 1. \-dplyr (local) foo() - 2. \-dplyr (local) bar() - 3. +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE)) - 4. \-dplyr:::mutate.data.frame(...) + 1. +-dplyr (local) foo() + 2. | \-dplyr (local) bar() + 3. | \-df %>% group_by(x = f(1):n()) %>% mutate(x = f(1, base = FALSE)) + 4. +-dplyr::mutate(., x = f(1, base = FALSE)) + 5. \-dplyr:::mutate.data.frame(., x = f(1, base = FALSE)) [[4]] @@ -595,9 +610,10 @@ --- Backtrace: x - 1. \-dplyr (local) foo() - 2. \-dplyr (local) bar() - 3. +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE)) - 4. \-dplyr:::mutate.data.frame(...) + 1. +-dplyr (local) foo() + 2. | \-dplyr (local) bar() + 3. | \-df %>% group_by(x = f(1):n()) %>% mutate(x = f(1, base = FALSE)) + 4. +-dplyr::mutate(., x = f(1, base = FALSE)) + 5. \-dplyr:::mutate.data.frame(., x = f(1, base = FALSE)) diff --git a/tests/testthat/test-conditions.R b/tests/testthat/test-conditions.R index 0d9fa97ef7..50cc758488 100644 --- a/tests/testthat/test-conditions.R +++ b/tests/testthat/test-conditions.R @@ -80,8 +80,8 @@ test_that("warnings are collected for `last_dplyr_warnings()`", { reset_dplyr_warnings() expect_snapshot({ "Ungrouped" - df |> - mutate(x = f()) |> + df %>% + mutate(x = f()) %>% invisible() last_dplyr_warnings() }) @@ -89,9 +89,9 @@ test_that("warnings are collected for `last_dplyr_warnings()`", { reset_dplyr_warnings() expect_snapshot({ "Grouped" - df |> - group_by(id) |> - mutate(x = f()) |> + df %>% + group_by(id) %>% + mutate(x = f()) %>% invisible() last_dplyr_warnings() }) @@ -99,9 +99,9 @@ test_that("warnings are collected for `last_dplyr_warnings()`", { reset_dplyr_warnings() expect_snapshot({ "Rowwise" - df |> - rowwise() |> - mutate(x = f()) |> + df %>% + rowwise() %>% + mutate(x = f()) %>% invisible() last_dplyr_warnings() }) @@ -109,12 +109,12 @@ test_that("warnings are collected for `last_dplyr_warnings()`", { reset_dplyr_warnings() expect_snapshot({ "Multiple type of warnings within multiple verbs" - df |> - group_by(g = f():n()) |> - rowwise() |> - mutate(x = f()) |> - group_by(id) |> - mutate(x = f()) |> + df %>% + group_by(g = f():n()) %>% + rowwise() %>% + mutate(x = f()) %>% + group_by(id) %>% + mutate(x = f()) %>% invisible() last_dplyr_warnings() }) @@ -122,8 +122,8 @@ test_that("warnings are collected for `last_dplyr_warnings()`", { reset_dplyr_warnings() expect_snapshot({ "Truncated (1 more)" - df |> - rowwise() |> + df %>% + rowwise() %>% mutate(x = f()) last_dplyr_warnings(n = 1) }) @@ -132,8 +132,8 @@ test_that("warnings are collected for `last_dplyr_warnings()`", { expect_snapshot({ "Truncated (several more)" df <- tibble(id = 1:5) - df |> - rowwise() |> + df %>% + rowwise() %>% mutate(x = f()) last_dplyr_warnings(n = 1) }) @@ -160,8 +160,8 @@ test_that("complex backtraces with base and rlang warnings", { foo <- function() bar() bar <- function() { - df |> - group_by(x = f(1):n()) |> + df %>% + group_by(x = f(1):n()) %>% mutate(x = f(1, base = FALSE)) } @@ -181,8 +181,8 @@ test_that("`last_dplyr_warnings()` only records 5 backtraces", { df <- tibble(id = 1:10) expect_warning( - df |> - group_by(id) |> + df %>% + group_by(id) %>% mutate(x = f()) )