linear_time() creates a vector of linear time points with a specified
chronon (smallest time unit). This function is useful for creating custom
time representations that aren't covered by the convenience functions like
yearmonth() or yearweek().
Usage
linear_time(
data,
chronon = time_chronon(data),
discrete = TRUE,
calendar = time_calendar(data)
)Arguments
- data
Input data to convert to linear time. Can be:
Numeric values (interpreted as chronons since Unix epoch)
Character strings (parsed as dates/times)
Date or POSIXct objects
Other time objects
- chronon
A time unit expression representing the chronon (smallest indivisible time unit), evaluated in the context of
calendar. Use unquoted expressions likemonth(1L)orhour(1L). Chronons from a specific calendar can also be used (e.g.cal_isoweek$week(1L)). Defaults to the time chronon of the inputdata(time_chronon(data)).- discrete
Logical. If
TRUE(default), returns integer chronons since Unix epoch (discrete time model). IfFALSE, returns fractional chronons allowing representation of partial time units (continuous time model).- calendar
Calendar system used to evaluate
chrononandgranules. Defaults totime_calendar(data)for existing time objects. Common options include cal_gregorian and cal_isoweek.
See also
new_linear_time_fn()for creating reusable linear time functionsyearmonth(),yearquarter(),year()for Gregorian time representationsyearweek()for ISO 8601 week-based timecal_gregorian, cal_isoweek for calendar systems
Examples
# Hourly time
linear_time(
Sys.time(),
chronon = hour(1L)
)
#> <mixtime[1]>
#> [1] 2026-04-08 03h
# Monthly time
linear_time(
Sys.Date(),
chronon = month(1L)
)
#> <mixtime[1]>
#> [1] 2026 Apr
# Discrete vs continuous time
linear_time(Sys.time(), chronon = day(1L), discrete = TRUE)
#> <mixtime[1]>
#> [1] 2026-04-08
linear_time(Sys.time(), chronon = day(1L), discrete = FALSE)
#> <mixtime[1]>
#> [1] 2026-04-08 12.9%
# ISO week calendar with week-day structure
# TODO - needs default format strings to dispatch on calendar
# linear_time(
# Sys.Date(),
# chronon = day(1L),
# calendar = cal_isoweek
# )