DebugFnWE: Wrap function to capture arguments and environment of...

View source: R/DebugFn.R

DebugFnWER Documentation

Wrap function to capture arguments and environment of exception throwing function call for later debugging.

Description

Wrap fn, so it will save arguments and environment on failure. Please see: vignette("DebugFnW", package="wrapr").

Usage

DebugFnWE(saveDest, fn, ...)

Arguments

saveDest

where to write captured state (determined by type): NULL random temp file, character temp file, name globalenv() variable, and function triggers callback.

fn

function to call

...

arguments for fn

Value

wrapped function that captures state on error.

See Also

dump.frames, DebugFn, DebugFnW, DebugFnWE, DebugPrintFn, DebugFnE, DebugPrintFnE

Idea from: https://gist.github.com/nassimhaddad/c9c327d10a91dcf9a3370d30dff8ac3d

Examples


saveDest <- paste0(tempfile('debug'),'.RDS')
f <- function(i) { (1:10)[[i]] }
df <- DebugFnWE(saveDest, f)
# correct run
df(5)
# now re-run
# capture error on incorrect run
tryCatch(
   df(12),
   error = function(e) { print(e) })
# examine details
situation <- readRDS(saveDest)
str(situation)
# fix and re-run
situation$args[[1]] <- 6
do.call(situation$fn, situation$args, envir=situation$env)
# clean up
file.remove(saveDest)


WinVector/wrapr documentation built on Aug. 29, 2023, 4:51 a.m.