Taking your postβs title at face value, let blocks binds local variables to global instances in its header and makes a (temporary) local scope to run the block in. But thatβs not really what R is doing there. R is doing non-standard evaluation, which works more like implicit macros on argument expressions; unlike Julia, R arguments are lazily evaluated and make its way into the function as an expression you can opt to keep as one long enough for metaprogramming. Restricting names to a data.frameβs namespace is just one use case; it could also be used to provide strings for plot labels instead of evaluating variables.
Note that DataFramesMeta.@with requires you to write column symbols :x differently from existing variables x. Thatβs purposely engineered for the distinction, it does not imply that symbols are provided to macros with that syntax; in fact a simple @macroexpand x only sees :x in its body. The choice to incorporate the :x syntax also seems intended to clarify that youβre accessing a column name; a lot of confusion comes from Rβs standard vs nonstandard evaluation looking the same at the call site, even being turned on and off by an optional argument.
Someone suggested your StaticModules package - this package is my favorite solution for the DataFrame problem Create temporary local namespace? - #8 by CameronBieganek. The destructuring bind you illustrate in your solution is also useful but then becomes cumbersome when you have a large number of columns in the DataFrame.
For the specific example I described, this is a very nice solution:
This seems the most general solution. It doesnβt differentiate between column names and global variables as does DataFramesMeta but I assume decides symbol values based on scoping rules - this is also how R works as well.
Thanks for the transform! example - this is separately useful (similar to Rβs transform/mutate/within functions). The dot syntax is of course the obvious solution but my objective was to avoid writing the DataFrame name for each variable - largely for readability.