Usage
register_immunarch_method(
core,
family,
name,
register_family = TRUE,
required_cols = NULL,
need_repertoires = TRUE
)Arguments
- core
A function with signature
function(idata, ...). This is your core implementation; it must accept anImmunDataas the first argument and must not declareautojoin,format, orfeatures.- family
String. Method family name used for dispatch (e.g.,
"airr_stats").- name
String. Method name within the family (e.g.,
"lengths").- register_family
Logical (default
TRUE). IfTRUE, attempts to create/ensure the family environment by callingregister_airr_family()when available.- required_cols
Character vector of column names that must be present in
idata$annotations. Use this to declare the minimal input schema your core needs.- need_repertoires
Logical. Use this to declare the necessity of having aggregated repertoires.
Value
A function - the user-facing wrapper around core. Typical usage is to
assign it to the exported symbol of the method, e.g.:
airr_stats_lengths <- register_immunarch_method(...).
Details
Wrap a core implementation into a user-facing function and (optionally) register it in the in-memory method registry. The wrapper adds common arguments and runs safety checks so your core stays minimal.
What your core must look like
Signature:
function(idata, ...)Must not declare
autojoin,format, orfeatures- these are added by the wrapper.
What the wrapper adds
Common args from
im_common_args():autojoin,format,features(withautojoindefault controlled bygetOption("immunarch.autojoin", FALSE)).Validates
idatais an immundata::ImmunData object.Ensures all columns in
required_colsexist inidata$annotations.If
autojoin = TRUEand the result is a data frame containing the repertoire id column (immundata::imd_schema("repertoire")), joins repertoire metadata fromidata$repertoires.
Examples
# \dontrun{
# Minimal core implementation (must accept `idata`)
airr_stats_lengths_impl <- function(idata, seq_col = "cdr3_aa") {
dplyr::as_tibble(idata$annotations) |>
dplyr::distinct(.data[[immundata::imd_schema("repertoire")]], .data[[seq_col]]) |>
dplyr::mutate(seq_len = nchar(.data[[seq_col]])) |>
dplyr::count(.data[[immundata::imd_schema("repertoire")]], seq_len, name = "n")
}
# Register and expose a user-facing function
airr_stats_lengths <- register_immunarch_method(
core = airr_stats_lengths_impl,
family = "airr_stats",
name = "lengths",
required_cols = c("cdr3_aa", immundata::imd_schema("repertoire"))
)
#> Error in register_immunarch_method(core = airr_stats_lengths_impl, family = "airr_stats", name = "lengths", required_cols = c("cdr3_aa", immundata::imd_schema("repertoire"))): could not find function "register_immunarch_method"
# Optional: call via dispatcher
# make_airr_dispatcher("airr_stats")(idata = immdata, method = "lengths")
# }