MatchFunc2Args: Match Functions to Argument List

View source: R/25_MatchFunc2Args.R

MatchFunc2ArgsR Documentation

Match Functions to Argument List

Description

Identifies functions compatible with a given set of named arguments. A function is considered compatible if:

  • It has a ... parameter (loose matching), OR

  • All argument names in args_list exist in its formal parameters (strict matching, default behavior).

Usage

MatchFunc2Args(
  args_list,
  ...,
  name_only = FALSE,
  top_one_only = FALSE,
  dots_enabled = FALSE
)

Arguments

args_list

Named list of arguments to match. Must have non-empty names when non-empty.

...

Functions to test for compatibility.

name_only

Logical. If TRUE, return character vector of function names/identifiers instead of function objects. Default: FALSE.

top_one_only

Logical. If TRUE, return only the single best-matching function (ranked by number of matched parameters and parameter position). Default: FALSE.

dots_enabled

Logical. If TRUE, enable loose matching: any function with a ... parameter is considered compatible regardless of other parameter names. Default: FALSE (strict matching).

Value

  • name_only = FALSE, top_one_only = FALSE: List of compatible function objects

  • name_only = TRUE, top_one_only = FALSE: Character vector of function identifiers (named functions retain their symbol name; anonymous functions become "anonymous_<index>")

  • top_one_only = TRUE: Single function object or name (depending on name_only)

See Also

FilterArgs4Func() for filtering arguments to a function.(Reverse of this function)

Examples

## Not run: 
f1 <- function(a, b) a + b
f2 <- function(x, y, ...) x * y
f3 <- function(p, q) p - q

args <- list(a = 1, b = 2)

# Strict matching (default): returns f1 only
MatchFunc2Args(args, f1, f2, f3)

# Loose matching: returns f1 and f2 (both accept 'a' and 'b' via strict match or ...)
MatchFunc2Args(args, f1, f2, f3, dots_enabled = TRUE)

# Return only function names
MatchFunc2Args(args, f1, f2, name_only = TRUE)
# Returns: c("f1", "f2") when dots_enabled=TRUE

## End(Not run)

SigBridgeRUtils documentation built on Sept. 29, 2026, 5:09 p.m.