# How about new feature of \`:auto\` symbol of \`DataFrame\`?

**URL:** https://discourse.julialang.org/t/how-about-new-feature-of-auto-symbol-of-dataframe/72271
**Category:** Data
**Created:** [November 30, 2021, 5:15am UTC](https://discourse.julialang.org/t/how-about-new-feature-of-auto-symbol-of-dataframe/72271 "2021-11-30T05:15:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rmsmsgood](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rmsmsgood/32/20544_2.png) [@rmsmsgood](https://discourse.julialang.org/u/rmsmsgood)
#### Post date: [November 30, 2021, 5:15am UTC](https://discourse.julialang.org/t/how-about-new-feature-of-auto-symbol-of-dataframe/72271/1 "2021-11-30T05:15:49Z")

</div>

```julia
julia> DataFrame([1 0; 2 0], :auto)
2×2 DataFrame
 Row │ x1 x2    
     │ Int64 Int64
─────┼──────────────
   1 │ 1 0
   2 │ 2 0

```

Recently, the `:auto` symbol can be used to above result. I want new feature like this:

```julia
julia> x = [1,0]
2-element Vector{Int64}:
 1
 0

julia> y = [2,0]
2-element Vector{Int64}:
 2
 0

julia> DataFrame(x, y, :auto)
2×2 DataFrame
 Row │ x y     
     │ Int64 Int64
─────┼──────────────
   1 │ 1 0
   2 │ 2 0

```

For example, below long assignment frequently used in my work:

```julia
        time_evolution = DataFrame(
n_S_ = n_S_, n_E_ = n_E_, n_I_ = n_I_, n_R_ = n_R_, n_V_ = n_V_, n_hub_ = n_hub_, RT_ = RT_,
S_influx_ = S_influx_, I_influx_ = I_influx_, E_influx_ = E_influx_, R_influx_ = R_influx_, V_influx_ = V_influx_,
S_outflux_ = S_outflux_, I_outflux_ = I_outflux_, E_outflux_ = E_outflux_, R_outflux_ = R_outflux_, V_outflux_ = V_outflux_
        )

```

I wanna write that like below:

```julia
        time_evolution = DataFrame(
n_S_, n_E_, n_I_, n_R_, n_V_, n_hub, RT_,
S_influx_, I_influx_, E_influx_, R_influx_, V_influx_,
S_outflux_, I_outflux_, E_outflux_, R_outflux_, V_outflux_,
:auto
        )

```

How about that?

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [November 30, 2021, 6:25am UTC](https://discourse.julialang.org/t/how-about-new-feature-of-auto-symbol-of-dataframe/72271/2 "2021-11-30T06:25:30Z")

</div>

Your two examples are different: the first one `DataFrame(n_S = n_S, ...)` will have column names matching the names of your inputs. You can do that with a NamedTuple:

```julia
julia> x = rand(5); y = rand(5);

julia> DataFrame((; x, y))
5×2 DataFrame
 Row │ x y        
     │ Float64 Float64  
─────┼────────────────────
   1 │ 0.67518 0.269185
   2 │ 0.173524 0.554611
   3 │ 0.43453 0.241942
   4 │ 0.133013 0.273849
   5 │ 0.977161 0.822356

```

If you want `:auto`, just concatenate to a matrix:

```julia

julia> DataFrame([x, y], :auto)
5×2 DataFrame
 Row │ x1 x2       
     │ Float64 Float64  
─────┼────────────────────
   1 │ 0.67518 0.269185
   2 │ 0.173524 0.554611
   3 │ 0.43453 0.241942
   4 │ 0.133013 0.273849
   5 │ 0.977161 0.822356

```

---

<div class="post-metadata">

### Author: ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)
#### Post date: [November 30, 2021, 6:28am UTC](https://discourse.julialang.org/t/how-about-new-feature-of-auto-symbol-of-dataframe/72271/3 "2021-11-30T06:28:49Z")

</div>

Functions don’t have access to the names of input variables. There _could_ be a macro to do this, though.

(The reason nilshg’s suggestion works is that `(; x )` is interpreted as `(; x=x )`, so the tuple stores the variable name)

---

<div class="post-metadata">

### Author: ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)
#### Post date: [November 30, 2021, 6:34am UTC](https://discourse.julialang.org/t/how-about-new-feature-of-auto-symbol-of-dataframe/72271/4 "2021-11-30T06:34:06Z")

</div>

If this gives the result you need:

```julia
DataFrame(n_S_ = n_S_, n_E_ = n_E_, n_I_ = n_I_, <...>)

```

then this should be equivalent:

```julia
DataFrame(; n_S_, n_E_, n_I_, <...>)

```
