recover_types: Recover the types of objects in scope when a function that...

Description Usage Arguments Details Value Examples

View source: R/recover_types.R

Description

Allows error recovery with specific lines and functions.

Usage

1

Arguments

fun

A function to test. Please supply as either an unquoted name, or as a character string.

args

A list of optional function arguments to evaluate the function with.

Details

This function exists due to difficulties in dealing with composed functions. A composed function routinely returns an error message without listing the function within that caused the error, leading to uninformative error messages. Rather than try to rewrite everything that already exists (and works rather well), this function allows you to evaluate everything that happened until the function crashed and recover the types of objects in the environment when it crashed. This is a less verbose and heavy version of recovery

Value

A list with the line caused the function to crash, and the list of types of objects in scope when the crash happened. Alternatively a success message if the function ran successfully.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
 dummy_fun <- function( x = 2,
                        y = "this_crashes",
                        z = 2 )
 {
 # these will run
 x = x + 2
 z = x + 3
 # this will crash due to y being type character
 x = y + z
 return(x)
 }

 recover_types(fun = dummy_fun, args = list(x = 5))
 # this also works with arguments unspecified
 recover_types(fun = dummy_fun)

JSzitas/recovery documentation built on April 3, 2021, 3:16 p.m.