vec_default_ptype2: Default cast and ptype2 methods

View source: R/type2.R

vec_default_castR Documentation

Default cast and ptype2 methods

Description

These functions are automatically called when no vec_ptype2() or vec_cast() method is implemented for a pair of types.

  • They apply special handling if one of the inputs is of type AsIs or sfc.

  • They attempt a number of fallbacks in cases where it would be too inconvenient to be strict:

    • If the class and attributes are the same they are considered compatible. vec_default_cast() returns x in this case.

    • In case of incompatible data frame classes, they fall back to data.frame. If an incompatible subclass of tibble is involved, they fall back to tbl_df.

  • Otherwise, an error is thrown with stop_incompatible_type() or stop_incompatible_cast().

Usage

vec_default_cast(x, to, ..., x_arg = "", to_arg = "", call = caller_env())

vec_default_ptype2(x, y, ..., x_arg = "", y_arg = "", call = caller_env())

Arguments

x

Vectors to cast.

to

Type to cast to. If NULL, x will be returned as is.

...

For vec_cast_common(), vectors to cast. For vec_cast(), vec_cast_default(), and vec_restore(), these dots are only for future extensions and should be empty.

x_arg

Argument name for x, used in error messages to inform the user about the locations of incompatible types (see stop_incompatible_type()).

to_arg

Argument name to used in error messages to inform the user about the locations of incompatible types (see stop_incompatible_type()).

call

The execution environment of a currently running function, e.g. caller_env(). The function will be mentioned in error messages as the source of the error. See the call argument of abort() for more information.


vctrs documentation built on May 29, 2024, 11:39 a.m.