| cpt_register_method | R Documentation |
Teaches cpt_detect() about a detector this package does not
(and often cannot) depend on: an engine that is not on CRAN, a Python
detector reached through reticulate, a deep-learning model, a
proprietary in-house method, or a hand-curated set of changepoints. The
registered method then works with everything built on the ggcpt
contract: autoplot(), the geoms, tidy()/glance()/
augment(), cpt_metrics(), ggcpt_compare(),
cpt_stability(), cpt_consensus(), cpt_benchmark()
and cpt_report().
cpt_register_method(
name,
fn,
change_in = "mean",
engine = "user",
citation = NULL,
capabilities = list(),
cp_convention = c("left", "right"),
overwrite = FALSE
)
cpt_unregister_method(name)
cpt_registered_methods()
name |
Method name, as it will be passed to |
fn |
A function called as A returned |
change_in |
Character vector of |
engine |
Name of the package or system supplying the detector, for
display in |
citation |
Optional citation string returned by
|
capabilities |
Optional named list of capability flags overriding the
defaults (all |
cp_convention |
|
overwrite |
Replace an existing registration of the same name?
Defaults to |
Invisibly, the method name.
cpt_registered_methods() returns a tibble with one row per
registered method (columns method, change_in,
engine, has_citation), or a zero-row tibble when none are
registered.
A registered method is visibly user-supplied: cpt_methods() gives it
status = "registered", print() on its results marks it, and
cpt_cite() reports the citation you supplied or states that none
was given. The package validates the shape of what your function
returns (through as_ggcpt(), which runs the same contract
checks as every built-in wrapper); it does not and cannot validate the
method.
as_ggcpt() to turn changepoints into a result
object without registering a method;
cpt_unregister_method();
cpt_registered_methods().
# A deliberately trivial detector: split at the largest jump.
cpt_register_method(
"biggest_jump",
fn = function(x, ...) which.max(abs(diff(x))),
change_in = "mean",
engine = "example",
citation = "No citation supplied (illustration only)."
)
set.seed(1)
fit <- cpt_detect(c(rnorm(50), rnorm(50, 5)), method = "biggest_jump")
fit
cpt_unregister_method("biggest_jump")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.