knownOperations: Get or set loaders for operations/arrays

View source: R/knownOperations.R

knownOperationsR Documentation

Get or set loaders for operations/arrays

Description

Get or set loading functions for operations or arrays that were saved into the HDF5 file. This enables third-party packages to modify the chihaya framework for their own purposes.

Usage

knownOperations(operations)

knownArrays(arrays)

Arguments

operations

Named list of loading functions for operations. Each function should accept the same arguments as loadDelayed and return a matrix-like object. Names should match the delayed_operation string used to save the operation to file.

arrays

Named list of loading functions for arrays. Each function should accept the same arguments as loadDelayed and return a matrix-like object. Names should match the delayed_array string used to save the array to file.

Details

This function can be used to modify the loading procedure for existing operations/arrays or to add new loaders for new arrays.

Custom arrays should use a "custom " prefix in the name to ensure that they do not clash with future additions to the chihaya specification. If an instance of a custom array contains an r_package scalar string dataset inside its HDF5 group, the string is assumed to hold the name of the package that implements its loading handler; if this package is installed, it will be automatically loaded and used by loadDelayed.

Custom operations can be added, but they are not currently supported via validate, so it is assumed that such operations will be created outside of saveDelayed.

Value

If operations is missing, customLoadOperations will return a list of the current custom operations that have been registered with chihaya. If operations is provided, it is used to define the set of custom operations, and the previous set of operations is returned. The same approach is used for arrays in customLoadArrays.

Author(s)

Aaron Lun

Examples

library(HDF5Array)
X <- rsparsematrix(100, 20, 0.1)
Y <- DelayedArray(X)
Z <- log2(Y + 1)

temp <- tempfile(fileext=".h5")
saveDelayed(Z, temp)

# Overriding an existing operation:
ops <- knownOperations()
old_unary <- ops[["unary math"]]
ops[["unary math"]] <- function(file, path) {
    cat("WHEE!\n")
    old_unary(file, path)
}
old <- knownOperations(ops)

# Prints our little message:
loadDelayed(temp)

# Setting it back.
knownOperations(old)


LTLA/DelayedArraySaver documentation built on Sept. 19, 2024, 1:37 p.m.