PumasAI / SummaryTables.jl

A Julia package for creating publication-ready summary tables in HTML, docx, LaTeX and Typst
https://pumasai.github.io/SummaryTables.jl/
MIT License
65 stars 2 forks source link

Specify columns as strings? #44

Open devmotion opened 1 month ago

devmotion commented 1 month ago

Related to #43, I noticed that columns can't be specified as strings:

julia> table_one(pkpain_df, names(pkpain_df); show_n=true)
ERROR: MethodError: no method matching SummaryTables.Analysis(::String, ::DataFrame)

Closest candidates are:
  SummaryTables.Analysis(::Any, ::Any, ::Any)
   @ SummaryTables ~/.julia/packages/SummaryTables/WKLcB/src/table_one.jl:82
  SummaryTables.Analysis(::Symbol, ::DataFrame)
   @ SummaryTables ~/.julia/packages/SummaryTables/WKLcB/src/table_one.jl:87
  SummaryTables.Analysis(::Symbol, ::Any, ::DataFrame)
   @ SummaryTables ~/.julia/packages/SummaryTables/WKLcB/src/table_one.jl:96
  ...

Stacktrace:
 [1] (::SummaryTables.var"#32#33"{DataFrame})(x::String)
   @ SummaryTables ~/.julia/packages/SummaryTables/WKLcB/src/table_one.jl:117
 [2] iterate
   @ ./generator.jl:47 [inlined]
 [3] _collect
   @ ./array.jl:854 [inlined]
 [4] collect_similar
   @ ./array.jl:763 [inlined]
 [5] map
   @ ./abstractarray.jl:3285 [inlined]
 [6] make_analyses
   @ ~/.julia/packages/SummaryTables/WKLcB/src/table_one.jl:117 [inlined]
 [7] table_one(table::DataFrame, analyses::Vector{…}; groupby::Vector{…}, show_overall::Bool, show_pvalues::Bool, show_tests::Bool, show_confints::Bool, show_n::Bool, compare_groups::Vector{…}, nonnormal::Vector{…}, minmax::Vector{…}, tests::@NamedTuple{…}, combine::MultipleTesting.Fisher, sort::Bool, celltable_kws::@Kwargs{})
   @ SummaryTables ~/.julia/packages/SummaryTables/WKLcB/src/table_one.jl:263
 [8] top-level scope
   @ REPL[120]:1
Some type information was truncated. Use `show(err)` to see complete types.

In my use case this would have been convenient (arguably names(df) is a bit simpler than propertynames(df)).

jkrumbiegel commented 1 month ago

Good point, I'll add the option to use strings as well. When you have column names with spaces (I guess you shouldn't but...), symbols are also not easy to use.