Skip to contents

Run a call once normally, run it again with named function bindings replaced for the duration of the call, then compare the patched result against the original result.

Usage

with_patch(
  expr,
  patches,
  ignore = character(),
  tolerance = sqrt(.Machine$double.eps)
)

Arguments

expr

A function call to evaluate.

patches

A named list of replacement functions. Each name is the function binding to replace while evaluating expr.

ignore

Character vector of top-level fields to ignore when comparing list results. Passed to compare_call().

tolerance

Single non-negative numeric tolerance passed to compare_call().

Value

An object of class insider_patch, returned invisibly after printing.

Examples

local({
  helper <- function(x) x + 1
  run <- function(x) helper(x)
  with_patch(
    run(10),
    patches = list(helper = function(x) x + 100)
  )
})
#> 
#> ── insideR patch ───────────────────────────────────────────────────────────────
#> Call: `run(10)`
#> Patched function: `helper()`
#> helper(): session-local function, not part of an installed package
#> 
#> ── insideR comparison ──────────────────────────────────────────────────────────
#> Status: structural_difference
#> all.equal() reports structural differences between custom_result and
#> original_result.
#> 
#> ── Details ──
#> 
#> all.equal():
#> • Mean relative difference: 0.9
#> Numeric summary (beyond tolerance = 1.49011611938477e-08):
#> • Max absolute difference: 99
#> • Differing elements: 1 / 1
#> • Differing percent: 100%