Find the common type for a pair of vector types

vec_type2() finds the common type for a pair of vectors, or dies trying. It forms the foundation of the vctrs type system, along with vec_cast(). This powers type coercion but should not usually be called directly; instead call vec_type_common().

# S3 method for tbl_df
vec_type2(x, y)

vec_type2(x, y)

# S3 method for logical vec_type2(x, y)

# S3 method for integer vec_type2(x, y)

# S3 method for double vec_type2(x, y)

# S3 method for character vec_type2(x, y)

# S3 method for list vec_type2(x, y)

x, y

Either vector types; i.e.

Coercion rules

vctrs thinks of the vector types as forming a partially ordered set, or poset. Then finding the common type from a set of types is a matter of finding the least-upper-bound; if the least-upper-bound does not exist, there is no common type. This is the case for many pairs of 1d vectors.

The poset of the most important base vectors is shown below: (where datetime stands for POSIXt, and date for Date)

S3 dispatch

vec_type2() dispatches on both arguments. This is implemented by having methods of vec_type2(), e.g. vec_type2.integer() also be S3 generics, which call e.g. vec_type2.integer.double(). vec_type2.x.y() must return the same value as vec_type2.y.x(); this is currently not enforced, but should be tested.

Whenever you implemenet a vec_type2.new_class() generic/method, make sure to always provide vec_type2.new_class.default() ( which should call stop_incompatible_cast()) and vec_type2.new_class.vctrs_unspecified() (which should return x).

See vignette("s3-vector") for full details.

  • vec_type2.tbl_df
  • vec_type2
  • vec_type2.logical
  • vec_type2.integer
  • vec_type2.double
  • vec_type2.character
  • vec_type2.list
Documentation reproduced from package vctrs, version 0.1.0, License: GPL-3

Community examples

Looks like there are no examples yet.