R/arithmetic.R

Defines functions as.character.rdvec vec_arith.rdvec.numeric vec_arith.numeric.rdvec vec_arith.rdvec.rdvec vec_arith.rdvec

# Functions for all calendars

#' @export
#' @method vec_arith rdvec
vec_arith.rdvec <- function(op, x, y, ...) {
  UseMethod("vec_arith.rdvec", y)
}
#' @export
#' @method vec_arith.rdvec rdvec
vec_arith.rdvec.rdvec <- function(op, x, y, ...) {
  vec_arith(op, vec_data(x), vec_data(y))
}
#' @export
#' @method vec_arith.numeric rdvec
vec_arith.numeric.rdvec <- function(op, x, y, ...) {
  new_rdvec(
    vec_arith(op, x, vec_data(y)),
    get_calendar(y)
  )
}

#' @export
#' @method vec_arith.rdvec numeric
vec_arith.rdvec.numeric <- function(op, x, y, ...) {
  new_rdvec(
    vec_arith(op, vec_data(x), y),
    get_calendar(x)
  )
}

#' @export
as.character.rdvec <- function(x, ...) {
  format(x)
}

Try the calcal package in your browser

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

calcal documentation built on Feb. 25, 2026, 9:07 a.m.