tamper (version 1.0.0)

tamper: Easier Debugging of `magrittr` Pipes

Description

One difficulty of `magrittr` pipes is that they make debugging harder. If you don't always write correct code, and you use pipes, then you'll find tamper very useful. It is the `magrittr` specific alternative of the 'recover' function: when used with `options(error=tamper)`, after an error, it displays the whole pipeline, marks the place of the error, and helps saving the temporary results.

`tamper` is a function that can be used as an error callback, similarly to `utils::recover`. Tamper is pipe-friendly: it will show you the exact place of the error in the pipe.

Usage

tamper()

Arguments

Example

After running the following code:
options(error = tamper) f <- function(data) {
   data %>%
     (function(x) force(x)) %>%
     multiply_by(10) %>%
     add(10) %>%
     add("oh no!") %>%
     subtract(5) %>%
     divide_by(5)
} 1:10 %>%
   multiply_by(2) %>%
   f() %>%
   add(1:10)
you will see:
Error in add(., "oh no!") : non-numeric argument to binary operator Enter a pipe stage number, 1 to switch mode, or 0 to exit 1: Show full stack frames 2:    data %>%
3:      (function (x)
         force(x))(.) %>%
4:      multiply_by(., 10) %>%
5:      add(., 10) %>%
6: ->   add(., "oh no!") %>%
7:      subtract(., 5) %>%
8:      divide_by(., 5) Selection:
The problematic pipe stage is marked with an arrow. By pressing 1 (and ENTER) you can switch to a regular stack trace. If you want to save the temporary result from the pipe, choose the number at the arrow. This is the last pipe stage that has started before the error. Then you can save the value of the dot argument to the global environment:
assign("last_value", value, envir = .GlobalEnv)
When in non-interactive mode, tamper calls dump_pipes.

See Also

Other pipe.debuggers: dump_pipes; print.dump_pipes