Skip to content

Commit

Permalink
colwise functions support constants in formulas;
Browse files Browse the repository at this point in the history
closes #4374.
  • Loading branch information
romainfrancois committed May 20, 2019
1 parent 1ab6d81 commit de70321
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Expand Up @@ -2,6 +2,8 @@

* `rename_at()` handles empty selection (#4324).

* colwise functions support constants in formulas (#4374).

# dplyr 0.8.1

## Breaking changes
Expand Down
3 changes: 3 additions & 0 deletions inst/include/dplyr/hybrid/Expression.h
Expand Up @@ -139,6 +139,9 @@ class Expression {
if (TYPEOF(head) == CLOSXP && Rf_inherits(head, "inline_colwise_function")) {
dot_alias = CADR(expr);
expr = CADR(Rf_getAttrib(head, symbols::formula));
if (TYPEOF(expr) != LANGSXP) {
return;
}
head = CAR(expr);
}

Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-colwise-mutate.R
Expand Up @@ -405,3 +405,15 @@ test_that("summarise_at() can refer to local variables and columns (#4304)", {
})

})

test_that("colwise mutate handles formulas with constants (#4374)", {
expect_identical(
tibble(x = 12) %>% mutate_all(~ 42),
tibble(x = 42)
)
expect_identical(
tibble(x = 12) %>% mutate_at("x", ~ 42),
tibble(x = 42)
)
})

0 comments on commit de70321

Please sign in to comment.