diff --git a/R/scale-.R b/R/scale-.R index 66a0c91de4..aef461da93 100644 --- a/R/scale-.R +++ b/R/scale-.R @@ -1454,5 +1454,5 @@ trans_support_nbreaks <- function(trans) { } allow_lambda <- function(x) { - if (is_formula(x)) as_function(x) else x + if (is_formula(x, lhs = FALSE)) as_function(x) else x } diff --git a/tests/testthat/test-utilities.R b/tests/testthat/test-utilities.R index 107e22e063..4768bbf3da 100644 --- a/tests/testthat/test-utilities.R +++ b/tests/testthat/test-utilities.R @@ -188,6 +188,24 @@ test_that("expose/ignore_data() can round-trip a data.frame", { }) +test_that("allow_lambda converts the correct cases", { + + f <- allow_lambda(function(x) x + 1) + expect_equal(f(1), 2) + + f <- allow_lambda(~ .x + 1) + expect_equal(f(1), 2) + + f <- allow_lambda("A") + expect_equal(f, "A") + + f <- allow_lambda(expression(A)) + expect_equal(f, expression(A)) + + f <- allow_lambda(bquote("foo"~"bar")) + expect_equal(f, call("~", "foo", "bar")) +}) + test_that("summary method gives a nice summary", { # This test isn't important enough to break anything on CRAN skip_on_cran()