Skip to content

simple_table

Synopsis

simple_table creates a basic tabular display of raw data from a dataset. It allows users to select specific columns, optionally rename them, and control the alignment and appearance of subheaders.

Example Usage

julia
using SummaryTables

data = (
    id = 1:5,
    name = ["Alice", "Bob", "Charlie", "David", "Eve"],
    age = [34, 29, 42, 37, 25],
    score = [88, 92, 75, 80, 95]
)

simple_table(data)
id name age score
1 Alice 34 88
2 Bob 29 92
3 Charlie 42 75
4 David 37 80
5 Eve 25 95
julia
simple_table(data, [:id => "Identifier", :name => "Full Name", :age => "Age (years)"])
Identifier Full Name Age (years)
1 Alice 34
2 Bob 29
3 Charlie 42
4 David 37
5 Eve 25

Argument 1: table

The first argument can be any object compatible with the Tables.jl API. Some common examples:

DataFrame

julia
using DataFrames
using SummaryTables

data = DataFrame(a = [1, 2, 3], b = ["x", "y", "z"])

simple_table(data)
a b
1 x
2 y
3 z

NamedTuple of Vectors

julia
using SummaryTables

data = (; a = [1, 2, 3], b = ["x", "y", "z"])

simple_table(data)
a b
1 x
2 y
3 z

Vector of NamedTuples

julia
using SummaryTables

data = [(; a = 1, b = "x"), (; a = 2, b = "y"), (; a = 3, b = "z")]

simple_table(data)
a b
1 x
2 y
3 z

Keyword: halign

Controls the horizontal alignment of column contents. Accepts :left, :right, :center, or a vector of these values (one for each column).

julia
using SummaryTables

data = (; value = 1:3, sin = sin.(1:3), cos = cos.(1:3))
simple_table(data, halign = :right, round_mode = :digits, trailing_zeros = true)
value sin cos
1 0.841 0.540
2 0.909 -0.416
3 0.141 -0.990
julia
using SummaryTables

data = (; value = 1:3, sin = sin.(1:3), cos = cos.(1:3))
simple_table(data, halign = [:left, :right, :right], round_mode = :digits, trailing_zeros = true)
value sin cos
1 0.841 0.540
2 0.909 -0.416
3 0.141 -0.990

Keyword: subheaders

Allows specifying subheaders for columns. These must be of the same length as the number of displayed columns.

julia
using SummaryTables

data = (; value = 1:3, sin = sin.(1:3), cos = cos.(1:3))
simple_table(data, subheaders = ["Int64", "Float64", "Float64"], halign = :right)
value sin cos
Int64 Float64 Float64
1 0.841 0.54
2 0.909 -0.416
3 0.141 -0.99