View source: R/dist_structure-class.R
| validate_dist_structure | R Documentation |
Checks that x declares "dist_structure" in its class chain and
provides the three required generics: ncomponents(), component(),
and at least one of phi() or min_paths().
validate_dist_structure(x)
x |
An object claiming to satisfy the |
Useful in subclass constructors to fail fast with a clear error message rather than at first method dispatch (where the user sees opaque "no applicable method" errors). A typical pattern:
my_subclass <- function(...) {
obj <- structure(list(...), class = c("my_subclass", "dist_structure",
"univariate_dist", "continuous_dist", "dist"))
validate_dist_structure(obj)
obj
}
TRUE (invisibly) if all checks pass. Stops with an
informative error otherwise.
# Success: a valid dist_structure (any built-in topology shortcut works).
validate_dist_structure(series_dist(replicate(3,
algebraic.dist::exponential(1), simplify = FALSE)))
# Failure: an object that declares dist_structure but provides no
# primitives. Wrapped in tryCatch for the example's success status.
bad <- structure(list(),
class = c("not_a_real_class", "dist_structure",
"univariate_dist", "continuous_dist", "dist"))
tryCatch(validate_dist_structure(bad),
error = function(e) conditionMessage(e))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.