Description Usage Example See Also
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.
1 | tamper()
|
After running the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
you will see:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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:
1 | assign("last_value", value, envir = .GlobalEnv)
|
When in non-interactive mode, tamper
calls dump_pipes
.
Other pipe.debuggers: dump_pipes
;
print.dump_pipes
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.