nestedscales is the core package of a family for multi-level discrete representations of data, used in modelling, data processing and visualization. This page lists what the core provides in the current release, what the dimension packages add, and what is planned. It is updated with each release.
A nested scale represents one dimension of a dataset or model as a table of atoms, the finest units, with one column per coarser level, the frames. Every frame nests in the atoms. Frames may nest in each other (a tree: activity in division in section) or overlay each other (hours of the day and months of the year); every operation routes through the atoms, so both are handled alike.
The package covers three things:
scale_from_leaftable() builds a scale from a table;
scale_frames(), scale_units(),
scale_key(), scale_leaftable(),
scale_weights(), scale_rank() and
scale_atom_level() read it.scale_nests(),
scale_crosses(), scale_is_uniform();
scale_family() and scale_ancestry() list
parent-child pairs; scale_children(),
scale_parents(), scale_descendants() and
scale_ancestors() navigate.scale_share() and scale_coverage() report
weights and what fraction of a parent a subset keeps.NA at a level) and declared
residual units (scale_residuals()) are part of the
representation.filter_scale() and prune_scale() subset
and collapse a scale, keeping the record of coverage.SCALE_RULES: sum,
weighted_mean, mean, copy,
sd, share, logshare. Each is
defined in both directions, so aggregation and disaggregation are one
operation.register_scale_rule() records the rule for a named
value column, scoped per dimension, so a model’s parameters recast
without repeating the rule.recast_scale() converts data between any two levels of
a scale, or to the atoms of another scale that shares atom keys;
recast_to_atoms() and recast_from_atoms() are
its two halves; recast_crosswalk() runs the same engine
over a correspondence built elsewhere.scale_map() and scale_map_between() expose
the crosswalks; register_scale_map() installs exact or
hand-audited ones.join_scale() attaches labels, coarser levels, shares
and weights to a dataset.reconcile_scale() compares aggregated data with an
independent total and can balance the gap.scale_product() combines several scales into one
multi-dimensional index; recast_product(),
join_product() and filter_product() work over
it without materialising the product of atoms.cluster_scale(), cluster_contiguous(),
cluster_medoids() and cluster_sweep() group
units by their data and return the scale with the clusters as a new
level.as_scale_array() and as_scale_table() move
between long tables and dense arrays; write_scale_dataset()
and open_scale_dataset() store data as a partitioned Arrow
dataset together with its scales.data.frame, tibble,
data.table, dtplyr table or arrow dataset and returns the
same class; lazy inputs return a query.Calendar, a nested scale of time. A catalog of standard
calendars, construction from tokens, conversion from datetimes, sampled
and fiscal calendars, calendar plots.Geoscale, a nested scale of space. Region hierarchies from
data providers, geometry and area weights, maps.vignette("dimension-package") shows how to write
another one.Both are designed for optimization and simulation models, where the labelled time slices and regions become the index sets of variables and constraints (see energyRt).
The order is not fixed; items move up as the modelling packages need them.
ScaleProduct reserves joint_weights for a
weight that varies across axes together (an hourly profile that differs
by region). The slot is validated but not yet used by
recast_product().scale_from_leaftable(); a constructor taking breakpoints,
with the interval bounds kept as weights, would build them
directly.