Calling macro with runtime arguments: case of Query.jl

I’m using Query.jl a lot, and it is very convenient for dataframe processing. However I cannot understand how to call some of its operations with dynamically generated arguments. E.g. if there is a list of column names like names = [:a, :b, :c], how to group by them? df |> @groupby(names) does not work, neither do df |> @groupby($names) or similar. I managed to manually craft the expression, and pass the whole line to @eval like this:

group_key_expr = :( {$([:(_.$k) for k in names]...)} )
groups = @eval($(df) |> @groupby($group_key_expr) |> collect)

This works, however looks very far from obvious and convenient. Do I miss anything?

Maybe try out LightQuery.jl:

const names = (:a, :b, :c)
@> df
    Group(By(_, Names(names...))

Would you be amenable to a PR that changed Names to cols? That’s what DataFramesMeta, StatPlots, and JuliaDBMeta call that escaping operation.

Nope. Sorry, I don’t do abbreviations.

1 Like

Besides, it’s not an escaping operation, it’s a fully fledged function (there’s nothing to escape).

1 Like

So, no real solution with Query.jl for now?