| new_time_unit | R Documentation |
Define a new S7 class representing a time unit for use in a mixtime calendar.
Time units are the building blocks of calendars: each unit represents a
specific temporal component (e.g., day, month, year) and carries a step size
n. Units are combined via new_calendar() to form a complete calendar
system.
new_time_unit(
name,
parent = mt_unit,
package = topNamespaceName(parent.frame()),
properties = list(),
abstract = FALSE,
constructor = NULL,
validator = NULL
)
name |
A string naming the new S7 class (e.g., |
parent |
The parent S7 class. Should be one of |
package |
A string giving the package name that owns the class. Defaults to the name of the calling namespace, so typically does not need to be set explicitly. |
properties |
A named list of additional |
abstract |
Logical. If |
constructor |
A function to use as the class constructor, or |
validator |
A function of one argument ( |
Choose the parent class based on the type of time the unit represents:
mt_unit — abstract or calendar-only time (no timezone or location
context; e.g., Gregorian year or ISO week).
mt_tz_unit — civil time with a timezone (e.g., a clock hour that
needs tz to resolve wall-clock ambiguity).
mt_loc_unit — astronomical time with a geographic location (e.g., a
solar day tied to observer longitude/latitude).
Use new_time_unit() for units included in new_calendar(). Its generated
constructor records the calendar on each instance, including when the parent
has a custom constructor. A bare S7::new_class() constructor may only
forward ... to its parent and cannot infer the calling calendar.
An S7 class object, as returned by S7::new_class().
mt_unit, mt_tz_unit, mt_loc_unit for the base classes to
inherit from.
new_calendar() for assembling time units into a calendar.
unit_scheme() for naming a time unit (e.g. "day", "days" and "D").
S7::new_class() for the underlying S7 class constructor.
# An abstract unit with no properties
tu_my_seq <- new_time_unit("tu_my_seq", parent = mt_unit)
# A civil-time unit with an extra property
tu_my_quarter <- new_time_unit(
"tu_my_quarter",
parent = mt_tz_unit,
properties = list(
fiscal = S7::new_property(S7::class_logical, default = FALSE)
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.