Records, on the timeslice column itself, which Calendar its labels
belong to. The labels alone cannot say that: d001_h00 is a timeslice of
every calendar built on days and hours, whether a full year or a sample
of it. A bound column still behaves as a character vector and keeps the
link through row subsetting, mutate(), grouping, joins and row binding.
recast_calendar(), recast_to_timebase(), join_calendar() and
the tsl2*() conversions then stop when the data is bound to a different
calendar than the one they are given, and recast_calendar() binds its
result to the target calendar. Data that was never bound is handled as
before.
Arguments
- data
A
data.frame, tibble ordata.table.- calendar
The
Calendarthe labels belong to.- cols
Which columns to bind.
NULL(default) binds thetimeslicecolumn and any column named after a timeframe. Otherwise a character vector of"timeslice"or timeframe names, named by column where the column is called something else:c(slice = "timeslice").
Value
bind_calendar() returns data; calendar_link() a
data.frame with one row per bound column (column, scale, frame,
id); calendar_id() a single string.
Details
Every label is checked when binding; one that is not a timeslice of the
calendar is an error. calendar_link() reports what a table is bound to,
and calendar_id() gives the identity the link stores: the calendar's
name and a hash of its structure (timeframes and timeslices, not shares
or weights). nestedscales::unbind_scale() returns the columns to plain
character.
The link needs nestedscales 0.3.0 or later.
Examples
cal <- calendar("m12_h24")
calendar_id(cal)
#> [1] "m12_h24@2b46fc7d"
d <- data.frame(timeslice = calendar_timeslices(cal)[1:3], load = 1:3)
b <- bind_calendar(d, cal)
calendar_link(b)
#> column scale frame id
#> 1 timeslice m12_h24 timeslice m12_h24@2b46fc7d
# the same labels, another calendar: refused
other <- filter_calendar(cal, "MONTH", "m01")
try(join_calendar(b, other, timeframes = "MONTH"))
#> Error : the `timeslice` column is bound to 'm12_h24' [2b46fc7d], not to 'm12_h24[MONTH:m01]' [835d2a1a]
