Add constant folding
krlmlr opened this issue · 0 comments
krlmlr commented
For the purpose of dplyr expressions, any calls that do not contain references to columns (directly or via .data$
) can be folded into constants. I expect this to help with quite a few use cases, though it will be hard to get data for that.
The idea is to walk the expression tree, and for each call to do a post-order check if all arguments are constants. If yes, we evaluate the call and replace it with the value. We need to be a bit careful with NSE functions, but we can evaluate in an environment that fails on column access.
@jcrodriguez1989: I've seen rco. The scope here is a bit different, and I'd like to hear your perspective if I'm underappreciating the complexity of the problem here. Thanks!