Skip to content
Merged
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
3 changes: 2 additions & 1 deletion R/scale-.R
Original file line number Diff line number Diff line change
Expand Up @@ -1454,5 +1454,6 @@ trans_support_nbreaks <- function(trans) {
}

allow_lambda <- function(x) {
if (is_formula(x)) as_function(x) else x
# we check the 'call' class to prevent interpreting `bquote()` calls as a function
if (is_formula(x, lhs = FALSE) && !inherits(x, "call")) 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