-
Notifications
You must be signed in to change notification settings - Fork 116
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
r?ply issues #165
r?ply issues #165
Conversation
There's no way to fix this problem in general without breaking old code. For that reason, I think we need an additional argument to |
In what way does my implementation break old code? |
Can we please keep the discussion of the pull request in one place? Here is some more detailed feedback:
|
Thank you for your very concise input. I have addressed most of your remarks, please see the updated branch for the most recent changes.
If we agree on the code, I'll be glad to make a sausage and open a new pull request. |
It'd be great if we could keep everything in this one pull request instead of scattering it in multiple places - could you please merge the commits into this branch? |
They are in this branch, but the pull request is closed, so they don't show up. https://github.com/krlmlr/plyr/tree/fix/158-rply-expr |
That's annoying - reopened just so I can see the changes. |
See also these comparisons: https://github.com/krlmlr/plyr/compare/hadley:master...fix/158-rply-expr -- entire branch https://github.com/krlmlr/plyr/compare/hadley:14713fe...fix/158-rply-expr -- last bunch of commits |
|
||
result <- vector("list", length = .n) | ||
|
||
# The logic below is responsible for ascertaining that .expr is evaluated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this explanation - it's useful, and I now understand (and like!) your strategy. However, I think it would be better separated into its own function, like:
expr_to_fun <- function(x) {
expr <- substitute(x)
res <- force(x)
if (is.function(res)) {
list(f = res, val = res())
} else {
f <- eval.parent(substitute(function() expr))
list(f = f, val = res)
}
}
expr_to_fun(function() runif(10))
expr_to_fun(runif(10))
then that can easily be tested independently of r*ply
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. This should be doable, thanks to lazy evaluation. Will push to this branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, I had to change the implementation, see 1eaf74d. The reason can be seen in a small self-contained test I have prepared. This test fails, but works if line 20 is replaced by f2e <- .expr_to_fun(inc())
. Unfortunately, the code in the test is an extract of what is happening for, e.g., raply
or rdply
-- and rlply
if a generic worker function is used.
Indeed, with the current code |
squashed and optimized somewhat |
…less if it actually is an expression and not a function
Could you please rebase/merge, update docs with latest roxygen2 and open a new pull request? |
An attempt to seamlessly support both expressions and functions in the
r?ply
family, maintaining consistency for both side effects and output.Fixes #158 and #164