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.

source
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.

source

Reflection

Tables.columnsFunction
columns(table::Table)

Convert a Table into a NamedTuple of its columns.

source
columns(dataframe::FlexTable)

Convert a FlexTable into a NamedTuple of its columns.

source
TypedTables.columnnamesFunction
columnnames(table)

Return a tuple of the column names of a Table.

source
columnnames(table)

Return a tuple of the column names of a Table.

source

Property selection

TypedTables.getpropertiesFunction
getproperties(object, names::Tuple{Vararg{Symbol}})

Extract a set of properties with the given names from an object, returning a new object with just those properties.

Example

Extract properties a and c from a NamedTuple.

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

julia> getproperties(nt, (:a, :c))
(a = 1, c = false)
source
getproperties(names::Tuple{Vararg{Symbol}})

Return a function that extracts a set of properties with the given names from an object, returning a new object with just those properties.

Internally, the names are stored as a type parameter of a GetProperties object for the purpose of constant propagation. You may overload the propertytype function to control the type of the object that is returned, which by default will be a NamedTuple. See also getproperty.

Example

Extract properties a and c from a NamedTuple.

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

julia> getproperties((:a, :c))(nt)
(a = 1, c = false)
source
TypedTables.deletepropertyFunction
deleteproperty(object, name::Symbol)

Return a copy of object with the property with the given name removed.

Example

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

julia> deleteproperty(nt, :b)
(a = 1, c = false)
source
TypedTables.deletepropertiesFunction
deleteproperties(object, names::Tuple{Vararg{Symbol}})

Return a copy of object with the property with the given names removed.

Example

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

julia> deleteproperties(nt, (:b, :d))
(a = 1, c = false)
source

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
source
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` 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)
source