vctrs-conditions {vctrs} | R Documentation |
These functions are called for their side effect of raising errors and warnings. These conditions have custom classes and structures to make testing easier.
stop_incompatible_type(x, y, x_arg = "", y_arg = "", details = NULL, ..., message = NULL, .subclass = NULL) stop_incompatible_cast(x, y, details = NULL, ..., x_arg = "", to_arg = "", message = NULL, .subclass = NULL) stop_incompatible_op(op, x, y, details = NULL, ..., message = NULL, .subclass = NULL) stop_incompatible_size(x, y, x_size, y_size, x_arg = "", y_arg = "", details = NULL, ..., message = NULL, .subclass = NULL) maybe_lossy_cast(result, x, to, lossy = NULL, locations = NULL, details = NULL, ..., x_arg = "", to_arg = "", message = NULL, .subclass = NULL, .deprecation = FALSE) allow_lossy_cast(expr, x_ptype = NULL, to_ptype = NULL)
x, y |
Vectors |
details |
Any additional human readable details |
..., message, .subclass |
Only use these fields when creating a subclass. |
result |
The result of a potentially lossy cast. |
to |
Type to cast to. |
lossy |
A logical vector indicating which elements of Can also be a single |
locations |
An optional integer vector giving the
locations where |
.deprecation |
If |
x_ptype, to_ptype |
Suppress only the casting errors where |
subclass |
Use if you want to further customise the class |
stop_incompatible_*()
unconditionally raise an error of class
"vctrs_error_incompatible_*"
and "vctrs_error_incompatible"
.
By default, lossy casts are an error. Use allow_lossy_cast()
to
silence these errors and continue with the partial results. In this
case the lost values are typically set to NA
or to a lower value
resolution, depending on the type of cast.
Lossy cast errors are thrown by maybe_lossy_cast()
. Unlike
functions prefixed with stop_
, maybe_lossy_cast()
usually
returns a result. If a lossy cast is detected, it throws an error,
unless it's been wrapped in allow_lossy_cast()
. In that case, it
returns the result silently.
# Most of the time, `maybe_lossy_cast()` returns its input normally: maybe_lossy_cast(c("foo", "bar"), NULL, "", lossy = c(FALSE, FALSE)) # If `lossy` has any `TRUE`, an error is thrown: try(maybe_lossy_cast(c("foo", "bar"), NULL, "", lossy = c(FALSE, TRUE))) # Unless lossy casts are allowed: allow_lossy_cast( maybe_lossy_cast(c("foo", "bar"), NULL, "", lossy = c(FALSE, TRUE)) )