vec_coerce()
is a binary generic meant to power
automatic coercions in tidyverse and r-lib packages. Methods should:
Have symmetric coercion behaviour. The resulting type should be
identical on permutation of from
and to
.
Not necessarily be fully commutative: vec_coerce()
is expected
to return a vector as long as the first argument from
.
Differentiate between empty and non-empty vectors. Most of the time all the type information should be contained in attributes and the return type can be determined on empty vectors.
In some cases however the contents of the vector are necessary to determine the appropriate coercion (e.g. the contents of a character vector are needed to determine congruence with the levels of a factor).
Should warn about dangerous coercions with the class
"rlang_vec_coerce_wng"
so that coercion warnings can be
selectively muffled (see muffle_vec_coerce()
).
1 | vec_coerce(from, to)
|
from |
The vector to coerce. The return value should be a
vector as long as |
to |
The vector containing the type information to determine
the coercion of |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.