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

Support for decorators #131

Open
lorenzwalthert opened this issue Jan 28, 2022 · 5 comments
Open

Support for decorators #131

lorenzwalthert opened this issue Jan 28, 2022 · 5 comments

Comments

@lorenzwalthert
Copy link

For example like in Python. This would allow things like

# cache a function
@R.cache::cache()
slow_fun <- function() {
  ...
}

# parametrize tests with all combinations like pytetst
@testthat::cross(x = 1:2, y = 1:2) 
test_that('can create prod', {
  expect_equal(
    my_prod(x, y), 
    x * y
  )
})
@nfultz
Copy link

nfultz commented Jan 28, 2022

couple thoughts

  1. the at sign is already taken for S4
  2. In python, it only works with def and not lambda. R's function works closer to lambda.
  3. You can already write "setter" functions eg how names()<- and class()<- work. They are not exactly the same, but could be used to do similar things.

@lorenzwalthert
Copy link
Author

lorenzwalthert commented Jan 28, 2022

Thanks @nfultz. I know it's already taken for S4, but I think it would be still possible, since with S4, it's always within an expression as far as I know, e.g. x@y, and never @y, e.g. as the first token on a line. Right? There are symbols in R that have multiple meanings depending on the context, e.g. + as an infix operator for two arguments or as a sign.

@ColinFay
Copy link

Would you be ok with explaining this to someone not knowing Python and that doesn't know what decorators are? :)

@nfultz
Copy link

nfultz commented Jan 28, 2022 via email

@HenrikBengtsson
Copy link
Owner

Potential related to this, is https://github.com/dirkschumacher/defmacro. It might provide a way to declare these this using R syntax.

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

No branches or pull requests

4 participants