filter_calendar() and [ record the calendar they subset in
meta$sampled_from. The record is a named list with the name of the
source and its id (calendar_id()). A subset of a subset keeps the
first record, so the source is always the complete calendar the
timeslices come from, not an intermediate subset. prune_calendar()
and upgrade_calendar() carry the record.
Arguments
- calendar
A
Calendar.- record
FALSE(default) returns the source calendar;TRUEreturns the record, a list withnameandid, without rebuilding anything.
Value
The source Calendar: the stored one when the record holds
it, otherwise calendar(name) when its identity matches the recorded
id. NULL for a calendar that is not a subset and for a subset stored
before the source was recorded. NULL, with a message naming the
recorded name and identity, when the catalog does not have that
calendar any more. With record = TRUE, a list with name and id,
or NULL.
Details
A source that the catalog reproduces is recorded by name and identity
alone, and calendar_source() rebuilds it with calendar(name). That is
the case when the name is a catalog id and calendar(name) gives the
same calendar: the same leaftable, timeframes, members and member tables,
and the same meta apart from desc. Any other source (a hand-built
calendar, a catalog design built with another year_start,
utc_offset_minutes or year_fraction, one with further meta entries)
cannot be rebuilt from its name, so the record also holds the calendar
itself, as calendar.
The source is what places the timeslices of a subset in time: the subset
holds a few days of the year, the source says which days the year has.
The record is not part of the identity of the calendar
(calendar_id()). It is a different field from a free-form
meta$source entry, which is left as given.
Definition files
A record of a catalog source is plain text, so a subset of a catalog
calendar is written by nestedscales::write_scale() and read back with
its source. A record that holds the calendar itself is written too, but
the calendar does not travel in the file: only its name and identity do.
Read back, such a subset keeps the record, marked rebuild = FALSE, and
calendar_source() returns NULL with a message. The catalog is not
consulted for it: the calendar was kept because the catalog does not
reproduce the source, and a catalog design of the same name built with
other options has the same identity. This is the one limitation; a
subset that must keep a source of its own is saved with saveRDS().
Examples
cal <- calendar("d365_h24")
two <- filter_calendar(cal, "YDAY", c("d015", "d196"))
calendar_source(two, record = TRUE)
#> $name
#> [1] "d365_h24"
#>
#> $id
#> [1] "d365_h24@bdfea512"
#>
identical(calendar_leaftable(calendar_source(two)), calendar_leaftable(cal))
#> [1] TRUE
one <- filter_calendar(two, "YDAY", "d015")
calendar_source(one, record = TRUE)
#> $name
#> [1] "d365_h24"
#>
#> $id
#> [1] "d365_h24@bdfea512"
#>
calendar_source(cal)
#> NULL
