I couldn’t install the package so I decided to try to write something I’ve been thinking about for some time.
I tested it very little. I don’t know how general this is, but it should work for all “table” forms
Edit: this performs better by avoiding some allocations
function expand1(ndf, col)
df2nt(df)=(;zip(Symbol.(names(df)),eachcol(df))...)
rexp=findall(er-> er[col] isa DataFrame, eachrow(ndf))
foreach(subdf->rename!(n->string(col,'.')*n ,subdf), ndf[rexp,col])
rt=Tables.dictrowtable(vcat(df2nt.(ndf[rexp,col])...))
edf=hcat(ndf[rexp,Not(col)],DataFrame(rt))
iexp=findall.(>(1),map(r-> [er isa Vector ? length(er) : 1 for er in r],values.(eachrow(edf))))
edfp=mapreduce(r->flatten(edf[r:r,:],iexp[r]), vcat,1: nrow(edf))
nedfp=select(filter(er-> !isa(er[col] , DataFrame), ndf),Not(col))
vcat(nedfp,edfp,cols=:union)
end
this should avoid mutations to the original dataframe (sub-dataframe names)
function expand2(ndf, col)
df2nt(sdf)=(;zip(Symbol.(string.(col,'.',names(sdf))),eachcol(sdf))...)
rexp=findall(er-> er[col] isa DataFrame, eachrow(ndf))
rt=Tables.dictrowtable(vcat(df2nt.(ndf[rexp,col])...))
edf=hcat(ndf[rexp,Not(col)],DataFrame(rt))
iexp=findall.(>(1),map(r-> [er isa Vector ? length(er) : 1 for er in r],values.(eachrow(edf))))
edfp=mapreduce(r->flatten(edf[r:r,:],iexp[r]), vcat,1: nrow(edf))
nedfp=select(filter(er-> !isa(er[col] , DataFrame), ndf),Not(col))
vcat(nedfp,edfp,cols=:union)
end