coerce_safe {na.tools} | R Documentation |
coerce_safe
Description
Coerce values in a safe, non-destructive and consistent way.
Usage
coerce_safe(object, class, alert = stop, ..., alert_irreversible = alert,
alert_na = alert)
Arguments
object |
to be coerced |
class |
character; class to which |
alert |
function to use to raise exceptions: (Default: |
... |
unused |
alert_irreversible |
function to raise alert when coercion is not reversible. See Details. |
alert_na |
function to raise when
Safe means that coercison:
By default, |
Value
object
coerced to class
but ensured that there has been no loss in data
and no additional Missonve values introduced.
Note
There must be a as
method to the reverse coercion for this function to work.
See Also
methods::as 'coercion::try_as()“
Examples
## Not run:
# Error
coerce_safe(1.01, "integer") # 1.01 != 1
coerce_safe( c("1","2","a"), "integer" )
## End(Not run)