R/to_from_zooreg.R

Defines functions ts_zooreg ts_dts.zooreg ts_zooreg_dts

Documented in ts_zooreg

register_class("zooreg")

# to ---------------------------------------------------------------------------

#' Convert to Class
#' @noRd
ts_zooreg_dts <- function(x) {
  stopifnot(requireNamespace("zoo"))
  zoo::as.zoo(ts_ts(x))
}


# from -------------------------------------------------------------------------

#' @export
#' @method ts_dts zooreg
ts_dts.zooreg <- function(x) {
  stopifnot(requireNamespace("zoo"))
  stopifnot(requireNamespace("xts"))
  ts_dts(as.ts(x))
}


# main converter ---------------------------------------------------------------

#' @name ts_ts
#' @export
ts_zooreg <- function(x) {
  check_ts_boxable(x)
  if (relevant_class(x) == "zooreg") {
    return(x)
  }
  ts_zooreg_dts(ts_dts(x))
}

Try the tsbox package in your browser

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

tsbox documentation built on May 31, 2023, 6:41 p.m.