buildNameCallback: Build a custom writeback function that writes state into a...

Description Usage Arguments Value Examples

View source: R/DebugFn.R

Description

Build a custom writeback function that writes state into a user named variable.

Usage

1

Arguments

varName

character where to write captured state

Value

writeback function for use with functions such as DebugFnW

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# user function
f <- function(i) { (1:10)[[i]] }
# capture last error in variable called "lastError"
writeBack <- buildNameCallback('lastError')
# wrap function with writeBack
df <- DebugFnW(writeBack,f)
# capture error (Note: tryCatch not needed for user code!)
tryCatch(
  df(12),
   error = function(e) { print(e) })
# examine error
str(lastError)
# redo call, perhaps debugging
tryCatch(
 do.call(lastError$fn_name, lastError$args),
   error = function(e) { print(e) })

WinVector/wrapr documentation built on Feb. 17, 2019, 9:37 p.m.