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.Table
— TypeTable(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 NamedTuple
s 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.FlexTable
— TypeFlexTable(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 NamedTuple
s 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.columns
— Functioncolumns(table::Table)
Convert a Table
into a NamedTuple
of its columns.
columns(dataframe::FlexTable)
Convert a FlexTable
into a NamedTuple
of its columns.
TypedTables.columnnames
— Functioncolumnnames(table)
Return a tuple of the column names of a Table
.
columnnames(table)
Return a tuple of the column names of a Table
.
Property selection
TypedTables.getproperties
— Functiongetproperties(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)
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)
TypedTables.deleteproperty
— Functiondeleteproperty(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)
TypedTables.deleteproperties
— Functiondeleteproperties(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)
Convenience macros
These macros return functions that can be applied to tables and rows.
TypedTables.@Compute
— Macro@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.@Select
— Macro@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 called
b, 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)