Learn R Programming

assertive.base (version 0.0-9)

coerce_to: Coerce variable to a different class

Description

Coerce the input to a different class, with a warning. More reliable then as, and supports coercion to multiple classes.

Usage

coerce_to(x, target_class, .xname = get_name_in_parent(x))

Arguments

x

Input to coerce.

target_class

The desired class of x. Multiple values allowed (see note).

.xname

Not intended to be used directly.

Value

The input x after attempted coercion to the target class.

See Also

is and as.

Examples

Run this code
# NOT RUN {
# Numbers can be coerced to characters but not to calls.
dont_stop(coerce_to(1:5, c("call", "character")))
# }

Run the code above in your browser using DataLab