Skip to content

Commit

Permalink
Reformat with tight () hugging
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan committed Feb 21, 2025
1 parent a162fe6 commit e643adf
Show file tree
Hide file tree
Showing 17 changed files with 416 additions and 630 deletions.
128 changes: 52 additions & 76 deletions tests/testthat/test-across.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,50 +234,36 @@ test_that("across() throws meaningful error with failure during expansion (#6534
test_that("across() gives meaningful messages", {
expect_snapshot({
# expanding
(
expect_error(
tibble(x = 1) %>%
summarise(across(where(is.numeric), 42))
)
)
(
expect_error(
tibble(x = 1) %>%
summarise(across(y, mean))
)
)
(expect_error(
tibble(x = 1) %>%
summarise(across(where(is.numeric), 42))
))
(expect_error(
tibble(x = 1) %>%
summarise(across(y, mean))
))

# computing
(
expect_error(
tibble(x = 1) %>%
summarise(res = across(where(is.numeric), 42))
)
)
(
expect_error(
tibble(x = 1) %>%
summarise(z = across(y, mean))
)
)
(
expect_error(
tibble(x = 1) %>%
summarise(res = sum(if_any(where(is.numeric), 42)))
)
)
(
expect_error(
tibble(x = 1) %>%
summarise(res = sum(if_all(~ mean(.x))))
)
)
(
expect_error(
tibble(x = 1) %>%
summarise(res = sum(if_any(~ mean(.x))))
)
)
(expect_error(
tibble(x = 1) %>%
summarise(res = across(where(is.numeric), 42))
))
(expect_error(
tibble(x = 1) %>%
summarise(z = across(y, mean))
))
(expect_error(
tibble(x = 1) %>%
summarise(res = sum(if_any(where(is.numeric), 42)))
))
(expect_error(
tibble(x = 1) %>%
summarise(res = sum(if_all(~ mean(.x))))
))
(expect_error(
tibble(x = 1) %>%
summarise(res = sum(if_any(~ mean(.x))))
))

(expect_error(across()))
(expect_error(c_across()))
Expand All @@ -290,43 +276,33 @@ test_that("across() gives meaningful messages", {
42
}
}
(
expect_error(
# expanding
tibble(x = 1:10, y = 11:20) %>%
summarise(across(everything(), error_fn))
)
)
(
expect_error(
# expanding
tibble(x = 1:10, y = 11:20) %>%
mutate(across(everything(), error_fn))
)
)
(expect_error(
# expanding
tibble(x = 1:10, y = 11:20) %>%
summarise(across(everything(), error_fn))
))
(expect_error(
# expanding
tibble(x = 1:10, y = 11:20) %>%
mutate(across(everything(), error_fn))
))

(
expect_error(
# evaluating
tibble(x = 1:10, y = 11:20) %>%
summarise(force(across(everything(), error_fn)))
)
)
(
expect_error(
# evaluating
tibble(x = 1:10, y = 11:20) %>%
mutate(force(across(everything(), error_fn)))
)
)
(expect_error(
# evaluating
tibble(x = 1:10, y = 11:20) %>%
summarise(force(across(everything(), error_fn)))
))
(expect_error(
# evaluating
tibble(x = 1:10, y = 11:20) %>%
mutate(force(across(everything(), error_fn)))
))

# name issue
(
expect_error(
tibble(x = 1) %>%
summarise(across(everything(), list(f = mean, f = mean)))
)
)
(expect_error(
tibble(x = 1) %>%
summarise(across(everything(), list(f = mean, f = mean)))
))
})
})

Expand Down
24 changes: 9 additions & 15 deletions tests/testthat/test-arrange.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,17 @@ test_that("local arrange sorts missing values to end", {
test_that("arrange() gives meaningful errors", {
expect_snapshot({
# duplicated column name
(
expect_error(
tibble(x = 1, x = 1, .name_repair = "minimal") %>% arrange(x)
)
)
(expect_error(
tibble(x = 1, x = 1, .name_repair = "minimal") %>% arrange(x)
))

# error in mutate() step
(
expect_error(
tibble(x = 1) %>% arrange(y)
)
)
(
expect_error(
tibble(x = 1) %>% arrange(rep(x, 2))
)
)
(expect_error(
tibble(x = 1) %>% arrange(y)
))
(expect_error(
tibble(x = 1) %>% arrange(rep(x, 2))
))
})
})

Expand Down
76 changes: 30 additions & 46 deletions tests/testthat/test-case-when.R
Original file line number Diff line number Diff line change
Expand Up @@ -271,54 +271,38 @@ test_that("throws chained errors when formula evaluation fails", {

test_that("case_when() give meaningful errors", {
expect_snapshot({
(
expect_error(
case_when(
c(TRUE, FALSE) ~ 1:3,
c(FALSE, TRUE) ~ 1:2
)
(expect_error(
case_when(
c(TRUE, FALSE) ~ 1:3,
c(FALSE, TRUE) ~ 1:2
)
)

(
expect_error(
case_when(
c(TRUE, FALSE) ~ 1,
c(FALSE, TRUE, FALSE) ~ 2,
c(FALSE, TRUE, FALSE, NA) ~ 3
)
)
)
))

(
expect_error(
case_when(50 ~ 1:3)
)
)
(
expect_error(
case_when(paste(50))
)
)
(
expect_error(
case_when(y ~ x, paste(50))
(expect_error(
case_when(
c(TRUE, FALSE) ~ 1,
c(FALSE, TRUE, FALSE) ~ 2,
c(FALSE, TRUE, FALSE, NA) ~ 3
)
)
(
expect_error(
case_when()
)
)
(
expect_error(
case_when(NULL)
)
)
(
expect_error(
case_when(~ 1:2)
)
)
))

(expect_error(
case_when(50 ~ 1:3)
))
(expect_error(
case_when(paste(50))
))
(expect_error(
case_when(y ~ x, paste(50))
))
(expect_error(
case_when()
))
(expect_error(
case_when(NULL)
))
(expect_error(
case_when(~ 1:2)
))
})
})
32 changes: 12 additions & 20 deletions tests/testthat/test-colwise-mutate.R
Original file line number Diff line number Diff line change
Expand Up @@ -408,31 +408,23 @@ test_that("_if isn't tripped up by columns named 'i' (#5330)", {
test_that("colwise mutate gives meaningful error messages", {
expect_snapshot({
# column not found
(
expect_error(
mutate_at(tibble(), "test", ~1)
)
)
(expect_error(
mutate_at(tibble(), "test", ~1)
))

# not summarising grouping variables
tbl <- tibble(gr1 = rep(1:2, 4), gr2 = rep(1:2, each = 4), x = 1:8)
tbl <- group_by(tbl, gr1)
(
expect_error(
summarise_at(tbl, vars(gr1), mean)
)
)
(expect_error(
summarise_at(tbl, vars(gr1), mean)
))

# improper additional arguments
(
expect_error(
mutate_all(mtcars, length, 0, 0)
)
)
(
expect_error(
mutate_all(mtcars, mean, na.rm = TRUE, na.rm = TRUE)
)
)
(expect_error(
mutate_all(mtcars, length, 0, 0)
))
(expect_error(
mutate_all(mtcars, mean, na.rm = TRUE, na.rm = TRUE)
))
})
})
66 changes: 25 additions & 41 deletions tests/testthat/test-colwise-select.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,48 +195,32 @@ test_that("colwise select() / rename() give meaningful errors", {
df <- tibble(x = 0L, y = 0.5, z = 1)

# colwise rename()
(
expect_error(
df %>% rename_all()
)
)
(
expect_error(
df %>% rename_if(is_integerish)
)
)
(
expect_error(
df %>% rename_at(vars(x:y))
)
)
(
expect_error(
df %>% rename_all(list(tolower, toupper))
)
)
(expect_error(
df %>% rename_all()
))
(expect_error(
df %>% rename_if(is_integerish)
))
(expect_error(
df %>% rename_at(vars(x:y))
))
(expect_error(
df %>% rename_all(list(tolower, toupper))
))

# colwise select()
(
expect_error(
df %>% select_all(list(tolower, toupper))
)
)
(
expect_error(
df %>% select_if(function(.x) 1)
)
)
(
expect_error(
df %>% select_if(function(.x) c(TRUE, TRUE))
)
)

(
expect_error(
data.frame() %>% select_all(.funs = 42)
)
)
(expect_error(
df %>% select_all(list(tolower, toupper))
))
(expect_error(
df %>% select_if(function(.x) 1)
))
(expect_error(
df %>% select_if(function(.x) c(TRUE, TRUE))
))

(expect_error(
data.frame() %>% select_all(.funs = 42)
))
})
})
Loading

0 comments on commit e643adf

Please sign in to comment.