jkrumbiegel / DataFrameMacros.jl

Macros that simplify working with DataFrames.jl
MIT License
61 stars 4 forks source link

Feature request: multiple column transform statements with @c or @m #19

Closed jeremiahpslewis closed 2 years ago

jeremiahpslewis commented 2 years ago
using DataFrameMacros
using DataFrames
using Chain

df = DataFrame(
    :a => [1, 2, 3, 4, 5],
    :b => [1, 2, 3, 4, 5],
    :c => [1, 2, 3, 4, 5],
)

# Works
@chain df begin
    @transform(:d = @c sum(:b))
    @transform(:e = @c sum(:c))
end

# Should work?
julia> @chain df begin
           @transform(:d = @c sum(:b), :e = @c sum(:c))
       end
ERROR: LoadError: UndefVarError: @c not defined
in expression starting at REPL[165]:2
jkrumbiegel commented 2 years ago

The problem there is that the @c macro is applied across the comma that separates your statements. For multiple commands it's therefore easier to list them in a begin end block. Or you wrap the right hand side of @c in parentheses. That's a Julia parsing limitation.