R/vctrs-difftime.R

Defines functions vec_restore.ethdifftime vec_proxy_compare.ethdifftime vec_cast.double.ethdifftime vec_cast.ethdifftime.double vec_cast.character.ethdifftime vec_cast.ethdifftime.character vec_cast.integer.ethdifftime vec_cast.ethdifftime.integer vec_ptype2.logical.ethdifftime vec_ptype2.ethdifftime.logical vec_ptype2.character.ethdifftime vec_ptype2.ethdifftime.character vec_ptype2.integer.ethdifftime vec_ptype2.ethdifftime.integer vec_ptype2.double.ethdifftime vec_ptype2.ethdifftime.double vec_ptype2.ethdifftime.ethdifftime new_ethdifftime

# Class ----

new_ethdifftime <- function(x = integer()) {
  if (!is.numeric(x)) {
    stop("`x` must be an integer vector.")
  }
  if (!is.integer(x)) {
    x <- as.integer(x)
  }
  vctrs::new_vctr(x, units = "days", class = "ethdifftime")
}


# Coercing ----

#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.ethdifftime.ethdifftime <- function(x, y, ...) new_ethdifftime()


#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.ethdifftime.double <- function(x, y, ...) double()

#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.double.ethdifftime <- function(x, y, ...) double()

#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.ethdifftime.integer <- function(x, y, ...) integer()

#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.integer.ethdifftime <- function(x, y, ...) integer()

#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.ethdifftime.character <- function(x, y, ...) character()

#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.character.ethdifftime <- function(x, y, ...) character()

#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.ethdifftime.logical <- function(x, y, ...) new_ethdifftime(integer())

#' @exportS3Method vctrs::vec_ptype2
vec_ptype2.logical.ethdifftime <- function(x, y, ...) new_ethdifftime(integer())



# Casting ----

#' @exportS3Method vctrs::vec_cast
vec_cast.ethdifftime.integer <- function(x, to, ...) new_ethdifftime(x)

#' @exportS3Method vctrs::vec_cast
vec_cast.integer.ethdifftime <- function(x, to, ...) vctrs::vec_data(x)

#' @exportS3Method vctrs::vec_cast
vec_cast.ethdifftime.character <- function(x, to, ...) new_ethdifftime(as.integer(x))

#' @exportS3Method vctrs::vec_cast
vec_cast.character.ethdifftime <- function(x, to, ...) as.character(vctrs::vec_data(x))

#' @exportS3Method vctrs::vec_cast
vec_cast.ethdifftime.double <- function(x, to, ...) new_ethdifftime(as.integer(x))

#' @exportS3Method vctrs::vec_cast
vec_cast.double.ethdifftime <- function(x, to, ...) as.numeric(vctrs::vec_data(x))



# Proxy ----


#' @exportS3Method vctrs::vec_proxy_compare
vec_proxy_compare.ethdifftime <- function(x, ...) as.difftime(vctrs::vec_data(x), units = "days")


#' @exportS3Method vctrs::vec_restore
vec_restore.ethdifftime <- function(x, to, ...) new_ethdifftime(x)

Try the ethiodate package in your browser

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

ethiodate documentation built on June 8, 2025, 1:29 p.m.