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

**URL:** https://discourse.julialang.org/t/tidierdata-jl-apply-transform-across-columns-while-retaining-access-to-other-variables-in-the-row/130115
**Category:** General Usage
**Tags:** tidier
**Created:** [June 22, 2025, 8:02pm UTC](https://discourse.julialang.org/t/tidierdata-jl-apply-transform-across-columns-while-retaining-access-to-other-variables-in-the-row/130115 "2025-06-22T20:02:24Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![lunafazio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lunafazio/32/217332_2.png) [@lunafazio](https://discourse.julialang.org/u/lunafazio)
#### Post date: [June 22, 2025, 8:02pm UTC](https://discourse.julialang.org/t/tidierdata-jl-apply-transform-across-columns-while-retaining-access-to-other-variables-in-the-row/130115/1 "2025-06-22T20:02:24Z")

</div>

My code is

```julia
@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."`)

---

<div class="post-metadata">

### Author: ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)
#### Post date: [June 22, 2025, 11:09pm UTC](https://discourse.julialang.org/t/tidierdata-jl-apply-transform-across-columns-while-retaining-access-to-other-variables-in-the-row/130115/2 "2025-06-22T23:09:46Z")

</div>

I haven’t tried it out, but perhaps you can try the [backtick notation](https://tidierorg.github.io/TidierData.jl/stable/examples/generated/UserGuide/column_names/#backtick-notation) mentioned in the docs.

---

<div class="post-metadata">

### Author: ![eteppo](https://avatars.discourse-cdn.com/v4/letter/e/90db22/32.png) [@eteppo](https://discourse.julialang.org/u/eteppo)
#### Post date: [June 22, 2025, 11:16pm UTC](https://discourse.julialang.org/t/tidierdata-jl-apply-transform-across-columns-while-retaining-access-to-other-variables-in-the-row/130115/3 "2025-06-22T23:16:04Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![lunafazio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lunafazio/32/217332_2.png) [@lunafazio](https://discourse.julialang.org/u/lunafazio)
#### Post date: [June 22, 2025, 11:22pm UTC](https://discourse.julialang.org/t/tidierdata-jl-apply-transform-across-columns-while-retaining-access-to-other-variables-in-the-row/130115/4 "2025-06-22T23:22:01Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lunafazio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lunafazio/32/217332_2.png) [@lunafazio](https://discourse.julialang.org/u/lunafazio)
#### Post date: [June 22, 2025, 11:25pm UTC](https://discourse.julialang.org/t/tidierdata-jl-apply-transform-across-columns-while-retaining-access-to-other-variables-in-the-row/130115/5 "2025-06-22T23:25:10Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![kdpsingh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdpsingh/32/215018_2.png) [@kdpsingh](https://discourse.julialang.org/u/kdpsingh)
#### Post date: [June 23, 2025, 5:23am UTC](https://discourse.julialang.org/t/tidierdata-jl-apply-transform-across-columns-while-retaining-access-to-other-variables-in-the-row/130115/6 "2025-06-23T05:23:25Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lunafazio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lunafazio/32/217332_2.png) [@lunafazio](https://discourse.julialang.org/u/lunafazio)
#### Post date: [June 27, 2025, 8:08am UTC](https://discourse.julialang.org/t/tidierdata-jl-apply-transform-across-columns-while-retaining-access-to-other-variables-in-the-row/130115/7 "2025-06-27T08:08:16Z")

</div>

I figured out a not-terribly-cumbersome way of doing this while staying in TidierData:

```julia
@chain df begin
    tmp = _
    @mutate(across(startswith("β"), x -> tmp.τ*x))
end

```

An annoying side-effect is that the variable gets defined in the outer scope so it’s not really temporary and can overwrite other things with the same name (is it possible to define chain-local variables?). Also, this would obviously not work properly if there’s any row reordering or grouping after assignment.

I assume a proper implementation would add all the dataframe’s columns to the local scope prior to any `transform` call? I would be happy to help implement this feature but I am still quite new to Julia so that may require too much handholding to be practical.

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [June 27, 2025, 9:03am UTC](https://discourse.julialang.org/t/tidierdata-jl-apply-transform-across-columns-while-retaining-access-to-other-variables-in-the-row/130115/8 "2025-06-27T09:03:43Z")

</div>

> [@lunafazio](#):
>
> ```julia
> @chain df begin
> tmp = _
> @mutate(across(startswith("β"), x -> tmp.τ*x))
> end
> 
> ```

You can use `_` multiple times, then you just have to assign the first argument, too:

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

```
