R/vctrs-date.R

Defines functions vec_restore.ethdate vec_proxy_compare.ethdate vec_cast.logical.ethdate vec_cast.ethdate.logical vec_cast.character.ethdate vec_cast.ethdate.character vec_cast.double.ethdate vec_cast.ethdate.double vec_cast.integer.ethdate vec_cast.ethdate.integer vec_ptype2.logical.ethdate vec_ptype2.ethdate.logical vec_ptype2.character.ethdate vec_ptype2.ethdate.character vec_ptype2.integer.ethdate vec_ptype2.ethdate.integer vec_ptype2.double.ethdate vec_ptype2.ethdate.double vec_ptype2.ethdate.ethdate new_ethdate

# Class ----

new_ethdate <- function(x = integer()) {
  if (inherits(x, "ethdate")) return(x)
  if (!is.numeric(x)) {
    stop("`x` must be an integer vector.")
  }
  if (!is.integer(x)) {
    x <- as.integer(x)
  }
  vctrs::new_vctr(x, class = "ethdate")
}


# Coercing ----

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

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

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

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

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

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

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

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

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


# Casting ----

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

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

#' @exportS3Method vctrs::vec_cast
vec_cast.ethdate.double <- function(x, to, ...) eth_date(x, ...)

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

#' @exportS3Method vctrs::vec_cast
vec_cast.ethdate.character <- function(x, to, ...) eth_date(x, ...)

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

#' @exportS3Method vctrs::vec_cast
vec_cast.ethdate.logical <- function(x, to, ...) new_ethdate(rep(NA_integer_, length(x)))

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


# Proxy ----


#' @exportS3Method vctrs::vec_proxy_compare
vec_proxy_compare.ethdate <- function(x, ...) vctrs::vec_data(x)


#' @exportS3Method vctrs::vec_restore
vec_restore.ethdate <- function(x, to, ...) eth_date(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.