-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.piar_index.R
56 lines (51 loc) · 1.31 KB
/
time.piar_index.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#' Get the time periods for a price index
#'
#' Methods to get and set the time periods for a price index.
#'
#' @param x A price index, as made by, e.g., [elemental_index()].
#' @param value A character vector, or something that can be coerced into one,
#' giving the replacement time periods for `x`.
#' @param ... Not currently used.
#'
#' @returns
#' `time()` returns a character vector with the time periods for a price index.
#' `start()` and `end()` return the first and last time period. `ntime()`
#' returns the number of time periods, analogous to `nlevels()`.
#'
#' The replacement method returns a copy of `x` with the time periods in
#' `value`.
#'
#' @importFrom stats time
#' @family index methods
#' @export
time.piar_index <- function(x, ...) {
x$time
}
#' @rdname time.piar_index
#' @export
`time<-` <- function(x, value) {
UseMethod("time<-")
}
#' @rdname time.piar_index
#' @export
`time<-.piar_index` <- function(x, value) {
x$time <- as.character(value)
validate_piar_index(x)
}
#' @rdname time.piar_index
#' @importFrom stats start
#' @export
start.piar_index <- function(x, ...) {
x$time[1L]
}
#' @rdname time.piar_index
#' @importFrom stats end
#' @export
end.piar_index <- function(x, ...) {
x$time[length(x$time)]
}
#' @rdname time.piar_index
#' @export
ntime <- function(x) {
length(time(x))
}