tests/testthat/test-25_MatchFunc2Args.R

test_that("multiplication works", {
  func1 <- function(a, b, c = 10L) a + b + c
  func2 <- function(x, y, ...) x * y
  func3 <- function(p, q) p - q
  # Argument list to match
  args <- list(a = 1L, b = 2L)
  res1 <- MatchFunc2Args(args, func1, func2, func3, name_only = TRUE)
  # Returns c("func1")
  # Anonymous function example
  res2 <- MatchFunc2Args(
    list(x = 5L, y = 3L),
    function(x, y) x + y,
    mean,
    name_only = TRUE
  )
  # Find compatible functions (returns function objects)
  res3 <- MatchFunc2Args(args, func1, func2, func3)
  # Returns list containing func1 (func3 lacks 'a' and 'b')
  # Get only function names/identifiers

  expect_equal(res1, "func1")
  expect_equal(res2, "function(x, y) x + y")
  expect_equal(res3, list(func1 = func1))
})

Try the SigBridgeRUtils package in your browser

Any scripts or data that you put into this service are public.

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