R/to_from_tibble.R

Defines functions ts_tbl as.tbl_df ts_tbl_dts

Documented in ts_tbl

register_class("tbl", "tbl_df")

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

#' Convert to Class
#' @noRd
ts_tbl_dts <- function(x) {
  stopifnot(requireNamespace("tibble"))
  tibble::as_tibble(as.data.frame(ts_data.table(x)))
}

#' Convert to Class
#' @noRd
as.tbl_df <- function(x) {
  stopifnot(requireNamespace("tibble"))
  tibble::as_tibble(x)
}

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

# not needed, uses ts_dts.data.frame


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

#' @name ts_ts
#' @export
ts_tbl <- function(x) {
  check_ts_boxable(x)
  if (relevant_class(x) == "tbl") {
    return(x)
  }
  ts_tbl_dts(ts_dts(x))
}
christophsax/tsbox documentation built on Sept. 22, 2023, 2:35 p.m.