Skip to content
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

Results of as_function() should inherit from "function" #735

Closed
richierocks opened this issue Mar 4, 2019 · 1 comment
Closed

Results of as_function() should inherit from "function" #735

richierocks opened this issue Mar 4, 2019 · 1 comment

Comments

@richierocks
Copy link
Contributor

@richierocks richierocks commented Mar 4, 2019

Functions created using as_function() do not have a class that includes "function", which means that inherits(fn, "function") confusingly returns FALSE.

library(rlang)
# An example function, created with as_function()
is_positive <- as_function(~ . > 0)
# It is a function, as expected
is.function(is_positive)
#> [1] TRUE
# It's also a lambda, as expected 
is_lambda(is_positive)
#> [1] TRUE
# It doesn't inherit from function, which isn't expected
inherits(is_positive, "function")
#> [1] FALSE

A possible fix would be to change this line

https://github.com/r-lib/rlang/blob/master/R/fn.R#L436

from

structure(fn, class = "rlang_lambda_function")

to

structure(fn, class = c("rlang_lambda_function", "function"))
@lionel-
Copy link
Member

@lionel- lionel- commented Mar 4, 2019

Agreed, would you like to send a PR for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants