Skip to contents

S3 generic that allows classes to customize deep sharing behavior. Override this for your class to control which slots/elements are traversed, force sharing of small objects, or transform objects before traversal.

Usage

shard_share_hook(x, ctx)

# Default S3 method
shard_share_hook(x, ctx)

Arguments

x

The object being traversed during deep sharing.

ctx

A context list containing:

path

Current node path string (e.g., "<root>$data@cache")

class

class(x) - the object's class vector

mode

'strict' or 'balanced' - sharing mode

min_bytes

Minimum size threshold for sharing

types

Character vector of enabled types for sharing

deep

Logical, always TRUE when hook is called

Value

A list with optional fields:

skip_slots

Character vector of S4 slot names to not traverse

skip_paths

Character vector of paths to not traverse

force_share_paths

Character vector of paths to force share (ignore min_bytes)

rewrite

Function(x) -> x to transform object before traversal

Return an empty list for default behavior (no customization).

Examples

# \donttest{
shard_share_hook.MyModelClass <- function(x, ctx) {
    list(
        skip_slots = "cache",
        force_share_paths = paste0(ctx$path, "@coefficients")
    )
}

shard_share_hook.LazyData <- function(x, ctx) {
    list(
        rewrite = function(obj) {
            obj$data <- as.matrix(obj$data)
            obj
        }
    )
}
# }