Recursive for loop to create data frame

I have some JuMP (optimisation package) variables which I want to save to a data frame to then save to a .csv file. My idea is to have a data frame that would look something like this:

df = DataFrame(JuMPVariable = Symbol[], Value = Number[],
        Dimensions = Tuple[])

I would then implement a for loop to push all the JuMP variables to the data frame. However, the dimensions of the JuMP variables vary, so I can’t just do:

for d = 1:length(jump_var)
     push!(df, symbol, jump_var[d], d)

In fact what I’ve written above wouldn’t work, I just can’t even begin to think about how I would do this. I think I need some sort of recursion, but have never done that before (at least not consciously).

If it helps, I would like my output to look something like this:

│ Row │ JuMPVariable │ Value  │ Dimensions  │
│     │ Symbol       │ Number │ Tuple       │
│ 1   │ Capacity     │ 1000   │ ("Wind",)   │
│ 2   │ OPEX         │ 100    │ ("Wind", 1) │
│ 3   │ OPEX         │ 100    │ ("Wind", 2) │
│ 4   │ OPEX         │ 100    │ ("Wind", 3) │
│ 5   │ OPEX         │ 100    │ ("Wind", 4) │
│ 6   │ OPEX         │ 100    │ ("PV", 1)   │

You just want something like:

for d = 1:length(jump_var)
    push!(df.JuMPVariable, symbol)
    push!(df.Value, jump_var[d])
    push!(df.Dimensions, d)

I don’t, because jump_var is an array with 1, 2, 3, or 4 dimensions. I could write an if statement that would go something like:

    for d1 =1:length(jump_var)
         do stuff
elseif length(size(jump_var)) == 2
     for d1 = 1:size(jump_var)[1]
          for d2 = 1:size(jump_var)[2]
               do stuff


But that’s obviously inconvenient. (The code above probably doesn’t work, I’m on my phone and that’s just what I think it should look like but I haven’t tested it).

For now I have decided to go with:

for (i,v) in enumarate(jump_var)
    push!(df.JuMPVariable, symbol)
    push!(df.Value, v)
    push!(df.Index, i)

Then I’ll have a data frame that I can write to a .csv file. I’m implicitly assuming that when I read from the csv file after I know the dimensions and so can use reshape to get my original array, but that’s not a problem. This might end up being a better way of doing it in any case.