TidierData.jl ― Apply transform across columns while retaining access to other variables in the row

My code is

@chain df begin    
    @mutate(across(startswith("β"), x -> τ*x))
end

where τ is another column in df, but it complains that it can’t find it in the Main module. Is there a way to indicate that I want the variable name to be taken from the dataframe in quesiton? Doing var"df.τ" or the backtick notation results in the same error.

(I tried _.τ but got the even more cryptic error that "This function should only be called inside of TidierData.jl macros.")

1 Like

I haven’t tried it out, but perhaps you can try the backtick notation mentioned in the docs.

Or this might require going back to DataFrames.jl. I remember across couldn’t do this previously. Maybe something like:

f(b, t) = t .* b
vars = Symbol.(names(df, r"^b"))
varpairs = [(v, :t) for v in vars]
transform(df, varpairs .=> f .=> vars)
1 Like

Yes, I tried this, it seems to look in Main just as if there were no backticks.

That’s a bummer, in dplyr that works out of the box. But thank you for the code! That should do the trick for now.

Thanks for flagging. Will take a look - this may be a limitation or bug within across() but should be fixable.

1 Like