By default recast_calendar() routes every conversion through the shared
instant grid (A -> base -> B). A registered override short-circuits that
route for one named calendar pair — the escape hatch for exact
nested-calendar arithmetic or anything the grid cannot express.
Usage
register_calendar_conversion(
source,
target,
fun,
from = lifecycle::deprecated(),
to = lifecycle::deprecated()
)
get_calendar_conversion(
source,
target,
from = lifecycle::deprecated(),
to = lifecycle::deprecated()
)
list_calendar_conversions()
clear_calendar_conversions(key = NULL)Arguments
- source, target
Calendar names (
meta$name) the override applies to.- fun
A function with signature
fun(x, from, to, ...)receiving the same arguments asrecast_calendar()and returning the recastdata.frame.NULLremoves a previously registered override.- from, to
Deprecated names of
sourceandtarget.- key
Optional character vector of
"from->to"keys to remove;NULL(default) clears everything.
Value
Invisibly, the registry key ("from->to").
get_calendar_conversion() returns the registered function or
NULL.
list_calendar_conversions() returns a data.frame with column
key.
Examples
register_calendar_conversion("m12", "q4", function(x, from, to, ...) {
# trivial exact nesting: quarters are consecutive month triples
q <- rep(sprintf("Q%d", 1:4), each = 3)
stats::aggregate(x[-1], list(timeslice = q[match(x$timeslice,
calendar_timeslices(from))]), sum)
})
"m12->q4" %in% list_calendar_conversions()$key
#> [1] TRUE
clear_calendar_conversions()
