Learn R Programming

shide (version 0.2.1)

shide-coercion: Coercion

Description

Double dispatch methods to support vctrs::vec_ptype2().

Usage

# S3 method for jdate
vec_ptype2(x, y, ..., x_arg = "", y_arg = "")

# S3 method for jdatetime vec_ptype2(x, y, ..., x_arg = "", y_arg = "")

Value

An object prototype if x and y can be safely coerced to the same prototype; otherwise it returns an error. See details for more information on coercion hierarchy for jdate and jdatetime.

Arguments

x, y

Vector types.

...

These dots are for future extensions and must be empty.

x_arg, y_arg

Argument names for x and y. These are used in error messages to inform the user about the locations of incompatible types (see stop_incompatible_type()).

Details

Coercion rules for jdate and jdatetime:

  • Combining a jdate and jdatetime yields a jdatetime.

  • When combining two jdatetime objects, the timezone is taken from the first non-local timezone.

Examples

Run this code
# jdate and jdatetime are compatible
c(jdate(), jdatetime(), jdatetime(tzone = "UTC"))
# jdate and Date are incompatible
try(c(jdate(), as.Date(NULL)))

Run the code above in your browser using DataLab