coerce_safe {na.tools} | R Documentation |
Coerce values in a safe, non-destructive and consistent way.
coerce_safe(object, class, alert = stop, ..., alert_irreversible = alert, alert_na = alert)
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, |
object
coerced to class
but ensured that there has been no loss in data
and no additional Missonve values introduced.
There must be a as
method to the reverse coercion for this function to work.
methods::as 'coercion::try_as()“
## Not run: # Error coerce_safe(1.01, "integer") # 1.01 != 1 coerce_safe( c("1","2","a"), "integer" ) ## End(Not run)