Description Usage Arguments Value Note See Also Examples
Coerce the input to a different class, with a warning. More reliable then
as
, and supports coercion to multiple classes.
1 | coerce_to(x, target_class, .xname = get_name_in_parent(x))
|
x |
Input to coerce. |
target_class |
The desired class of x. Multiple values allowed (see note). |
.xname |
Not intended to be used directly. |
The input x
after attempted coercion to the target class.
If x does not already have the target class, a warning is given
before coercion.
The function will try and convert the x
to each of the classes given
in target_class
, in order, until it succeeds or runs out of classes
to try. It will first try and convert x
using a dedicated
as.target_class
function if that exists. If it does not exist, or
throws an error then coerce_to
will try to use
as(x, target_class)
.
1 2 |
$`coerce_to(1:5, c("call", "character"))`
<simpleWarning: Coercing 1:5 to class 'call'.>
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.