Great questions. All the syntaxes within a chain block seem a bit clunky
julia> @chain df begin
copy
begin
for (ni, vi) in zip(n, v)
@rtransform! _ $ni = $vi
end
_
end
end
2×5 DataFrame
Row │ a b a_1 a_2 a_3
│ Int64 Int64 Int64 Int64 Int64
─────┼───────────────────────────────────
1 │ 1 3 1 3 1
2 │ 2 4 2 4 2
You can also leverage AsTable as follows
julia> @chain df begin
@rtransform $AsTable = (; (Symbol(n[i]) => v[i] for i in eachindex(n))...)
end
2×5 DataFrame
Row │ a b a_1 a_2 a_3
│ Int64 Int64 Int64 Int64 Int64
─────┼───────────────────────────────────
1 │ 1 3 1 2 3
2 │ 2 4 1 2 3
This is also very ugly. It looks like you can simplify things by using a Dict, though the order of columns might not be consistent, and performance will be hurt a little
julia> @chain df begin
@rtransform $AsTable = Dict(n[i] => v[i] for i in eachindex(n))
end
2×5 DataFrame
Row │ a b a_1 a_2 a_3
│ Int64 Int64 Int64 Int64 Int64
─────┼───────────────────────────────────
1 │ 1 3 1 2 3
2 │ 2 4 1 2 3