Skip to content

Only RHS-formula accepted as lambda function #6385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/scale-.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
18 changes: 18 additions & 0 deletions tests/testthat/test-utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading