From e44b9abdd8abf05127643db0384bf0e709877827 Mon Sep 17 00:00:00 2001 From: DavisVaughan Date: Wed, 1 Jun 2022 09:19:35 -0400 Subject: [PATCH] Update internal usage of `case_when()` --- R/utils-format.r | 6 +++--- data-raw/starwars.R | 6 +++--- tests/testthat/test-colwise-select.R | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/R/utils-format.r b/R/utils-format.r index 31353005b0..9f2af3dd3f 100644 --- a/R/utils-format.r +++ b/R/utils-format.r @@ -31,9 +31,9 @@ wrap <- function(..., indent = 0) { ruler <- function(width = getOption("width")) { x <- seq_len(width) y <- case_when( - x %% 10 == 0 ~ as.character((x %/% 10) %% 10), - x %% 5 == 0 ~ "+", - TRUE ~ "-" + x %% 10 == 0, as.character((x %/% 10) %% 10), + x %% 5 == 0, "+", + .default = "-" ) cat(y, "\n", sep = "") cat(x %% 10, "\n", sep = "") diff --git a/data-raw/starwars.R b/data-raw/starwars.R index 9e34c49312..4ff9956c20 100644 --- a/data-raw/starwars.R +++ b/data-raw/starwars.R @@ -83,9 +83,9 @@ starwars <- mutate(starwars, species = ifelse(name == "R4-P17", "Droid", species), # R4-P17 is a droid sex = ifelse(species == "Droid", "none", sex), # Droids don't have biological sex gender = case_when( - sex == "male" ~ "masculine", - sex == "female" ~ "feminine", - TRUE ~ unname(genders[name]) + sex == "male", "masculine", + sex == "female", "feminine", + .default = unname(genders[name]) ) ) diff --git a/tests/testthat/test-colwise-select.R b/tests/testthat/test-colwise-select.R index c1ed258667..d82e03eb8a 100644 --- a/tests/testthat/test-colwise-select.R +++ b/tests/testthat/test-colwise-select.R @@ -152,7 +152,7 @@ test_that("rename_at() handles empty selection (#4324)", { }) test_that("rename_all/at() call the function with simple character vector (#4459)", { - fun <- function(x) case_when(x == 'mpg' ~ 'fuel_efficiency', TRUE ~ x) + fun <- function(x) case_when(x == 'mpg', 'fuel_efficiency', .default = x) out <- rename_all(mtcars,fun) expect_equal(names(out)[1L], 'fuel_efficiency')