class_methods: Vector methods for 'mdate' objects

class_methodsR Documentation

Vector methods for mdate objects

Description

mdate and mduration objects are built on the vctrs package. They therefore subset, replace, concatenate, repeat, and deduplicate like ordinary vectors, and keep their class in data.frames, tibbles, and dplyr or tidyr pipelines (e.g. bind_rows(), unnest()).

Character strings, Date, and POSIXct values combine with mdate objects and are converted to mdate. A replacement value that cannot be read as a date raises an error, instead of a silent NA. An mdate converts to a character vector without loss, but conversion to an exact class, such as Date, needs an explicit resolution, see as.Date().

Usage

## S3 method for class 'mdate.mdate'
vec_ptype2(x, y, ...)

## S3 method for class 'mdate.mdate'
vec_cast(x, to, ...)

## S3 method for class 'mdate'
is.finite(x)

## S3 method for class 'mdate'
is.infinite(x)

## S3 method for class 'mdate'
is.nan(x)

Arguments

x, y

Vectors to combine or convert.

...

Passed on to other methods.

to

The type to convert to.

Details

unique() and duplicated() compare the annotated strings, not the sets of dates they expand to, so two values that could refer to the same date but are written differently (e.g. "2012-01" and "2012-01-01..2012-01-31") are treated as distinct.

is.finite() is TRUE for each date that is not missing, and is.infinite() and is.nan() are always FALSE: a messy date is imprecise, but it is never infinite or not a number. An open range, such as "..2012", is also finite. Packages such as ggplot2 call these functions on each column.

Value

An mdate object, except where the method converts to another type.

Examples

d <- as_messydate(c("2012-01-01", "2012-02-01", "2012-03-01"))
d[2]
d[2] <- "2012-02-02"
c(d, as_messydate("2012-04-01"))
c(d, as.Date("2012-05-01"))
rep(d, 2)
unique(as_messydate(c("2012-01-01", "2012-01-01", "2012-02-01")))
data.frame(event = c("a", "b", "c"), date = d)

messydates documentation built on Dec. 3, 2026, 5:09 p.m.