register_autoconvert_function: Add Autoconvert Function to Conversion Register

View source: R/typecheck.R

register_autoconvert_functionR Documentation

Add Autoconvert Function to Conversion Register

Description

Add functions that perform conversion to a desired class.

Whenever a Graph or a PipeOp is called with an object that does not conform to its declared input type, the "autoconvert register" is queried for functions that may turn the object into a desired type.

Conversion functions should try to avoid cloning.

Usage

register_autoconvert_function(cls, fun, packages = character(0))

Arguments

cls

character(1) The class that fun converts to.

fun

function The conversion function. Must take one argument and return an object of class cls, or possibly a sub-class as recognized by are_types_compatible().

packages

character The packages required to be loaded for fun to operate.

Value

NULL.

See Also

Other class hierarchy operations: add_class_hierarchy_cache(), reset_autoconvert_register(), reset_class_hierarchy_cache()

Examples

# This lets mlr3pipelines automatically try to convert a string into
# a `PipeOp` by querying the [`mlr_pipeops`] [`Dictionary`][mlr3misc::Dictionary].
# This is an example and not necessary, because mlr3pipelines adds it by default.
register_autoconvert_function("PipeOp", function(x) as_pipeop(x), packages = "mlr3pipelines")

mlr3pipelines documentation built on Sept. 30, 2024, 9:37 a.m.