R/summary.R

Defines functions format.summarycal summary.yearweek summary.yearmonth summary.yearquarter

#' @export
summary.yearquarter <- function(object, digits = 12L, ...) {
  x <- summary.default(unclass(object), digits = digits, ...)
  if (m <- match("NA's", names(x), 0L)) {
    NAs <- as.integer(x[m])
    x <- x[-m]
    attr(x, "NAs") <- NAs
  }
  output <- yearquarter(.Date(unclass(x)))
  attributes(output) <- attributes(x)
  class(output) <- c("summarycal", class(object))
  output
}

#' @export
summary.yearmonth <- function(object, digits = 12L, ...) {
  x <- summary.default(unclass(object), digits = digits, ...)
  if (m <- match("NA's", names(x), 0L)) {
    NAs <- as.integer(x[m])
    x <- x[-m]
    attr(x, "NAs") <- NAs
  }
  output <- yearmonth(.Date(unclass(x)))
  attributes(output) <- attributes(x)
  class(output) <- c("summarycal", class(object))
  output
}

#' @export
summary.yearweek <- function(object, digits = 12L, ...) {
  x <- summary.default(unclass(object), digits = digits, ...)
  if (m <- match("NA's", names(x), 0L)) {
    NAs <- as.integer(x[m])
    x <- x[-m]
    attr(x, "NAs") <- NAs
  }
  output <- yearweek(.Date(unclass(x)))
  attributes(output) <- attributes(x)
  class(output) <- c("summarycal", class(object))
  output
}

#' @export
format.summarycal <- function(x, ...) {
  xx <- x
  class(xx) <- class(x)[-1]
  xx <- c(
    format(xx),
    `NA's` = if (length(a <- attr(x, "NAs"))) as.character(a)
  )
  xx
}

Try the tsibble package in your browser

Any scripts or data that you put into this service are public.

tsibble documentation built on Feb. 9, 2026, 5:06 p.m.