Skip to content

Commit

Permalink
test that mutate does not evaluate when the group is empty #4088
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Jan 11, 2019
1 parent f6b571c commit 145add6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/testthat/test-mutate.r
Original file line number Diff line number Diff line change
Expand Up @@ -883,3 +883,19 @@ test_that("rlang lambda inherit from the data mask (#3843)", {
test_that("mutate() does not segfault when setting an unknown column to NULL (#4035)", {
expect_true(all_equal(mutate(mtcars, dummy = NULL), mtcars))
})

test_that("mutate() skips evaluation of R expression for empty groups (#4088)", {
count <- 0

d <- tibble(f = factor(c("a", "b"), levels = c("a", "b", "c"))) %>%
group_by(f)
res <- mutate(d, x = { count <<- count + 1; 675} )
expect_equal(count, 2L)

res <- tibble(f = factor(levels = c("a", "b", "c"))) %>%
group_by(f) %>%
mutate(x = { count <<- count + 1; 675} )
expect_equal(count, 3L)
expect_is(res$x, "numeric")

})

0 comments on commit 145add6

Please sign in to comment.