# API Reference

TypedTables.jl's API is intentially small, relying on existing interfaces to expose powerful and composable functionality.

The reference material can be easily accessed at the REPL, by pressing ? and typing in the name of the command.

## Constructing tables

# TypedTables.TableType.

Table(name1 = array1, ...)


Create a column-storage-based Table with column names name1, etc, from arrays array1, etc. The input arrays array1, etc, must share the same dimensionality and indices.

Table itself is an AbstractArray whose elements are NamedTuples of the form (name1 = first(array1), ...), etc. Rows of the table are obtained via standard array indexing table[i], and columns via table.name.

Table differs from FlexTable in that the columns are immutable - you may add, remove, rename and replace entire columns of a FlexTable, but not a Table. However, Table can access and iterate rows in local scope with fast, fully type-inferred code while FlexTable will be more efficient with a higher-order interface.

# TypedTables.FlexTableType.

FlexTable(name1 = array1, ...)


Create a column-storage-based FlexTable with column names name1, etc, from arrays array1, etc. The input arrays array1, etc, must share the same dimensionality and indices.

FlexTable itself is an AbstractArray whose elements are NamedTuples of the form (name1 = first(array1), ...), etc. Rows of the table are obtained via standard array indexing table[i], and columns via table.name.

FlexTable differs from Table in that the columns are mutable - you may add, remove, rename and replace entire columns of a FlexTable, but not a Table. However, Table can access and iterate rows in local scope with fast, fully type-inferred code while FlexTable will be more efficient with a higher-order interface.

## Reflection

# Tables.columnsFunction.

columns(table::Table)


Convert a Table into a NamedTuple of its columns.

columns(dataframe::FlexTable)


Convert a FlexTable into a NamedTuple of its columns.

# TypedTables.columnnamesFunction.

columnnames(table)


Return a tuple of the column names of a Table.

columnnames(table)


Return a tuple of the column names of a Table.

## Convenience macros

These macros return functions that can be applied to tables and rows.

# TypedTables.@ComputeMacro.

@Compute(...)


The @Compute macro returns a function which performs a calculation on the properties of an object, such as a NamedTuple.

The input expression is standard Julia code, with $ prepended to property names. For example. if you want to refer to a property named a then use $a in the expression.

Example

julia> nt = (a = 1, b = 2.0, c = false)
(a = 1, b = 2.0, c = false)

julia> @Compute($a +$b)(nt)
3.0


# TypedTables.@SelectMacro.

@Select(...)


The @Select macro returns a function which performs an arbitrary transformation of the properties of an object, such as a NamedTuple.

The input expression is a comma-seperated list of lhs = rhs pairs. The lhs is the name of the new property to calculate. The rhs is standard Julia code, with:(#= none:1 =# @cmd " prepended to input property names. For example. if you want to rename an input property ")ato be calledb, use@Select(b = :a).

As a special case, if a property is to be simply replicated the = rhs part can be dropped, for example @Select(a) is synomous with @Select(a = $a). Example julia> nt = (a = 1, b = 2.0, c = false) (a = 1, b = 2.0, c = false) julia> @Select(a, sum_a_b =$a + \$b)(nt)
(a = 1, sum_a_b = 3.0)
`