What's currently the recommended way to debug pipe chains?

magrittr

#1

What do you use to debug pipe chains? In this question:

pipecleaner was suggested, and it seems a pretty fine tool. Do you use this tool to debug your pipe chains? I remember seeing a few tweets on the topic of pipe chaining, but I can't find them anymore.


#2

I don't think there's a single "recommended" approach. @alistaire's pipecleaner, as you mentioned, is one

There's also ViewPipeSteps by Dan Ranzolin, which is another add-in that lets you see the results of each step of your pipe chain, which can be helpful:

@JohnMount has a post, Debugging Pipelines in R with Bizarro Pipe and Eager Assignment (below)

magrittr has a debug_pipe() function, but I've never actually used that one, to be honest…
https://magrittr.tidyverse.org/reference/debug_pipe.html


#3

If you want to see the piped value at a certain point, just stick a debug_pipe() call there.

100 %>%
  rnorm() %>%
  debug_pipe() %>%
  summary() %>%
  as.character()

In this example, this will show what's being passed to summary(), but that's not always enough info.

If you think a specific function is causing problems, use debug().

debug(summary)

100 %>%
  rnorm() %>%
  summary() %>% # Execution will pause and take you into the summary function
  as.character()

undebug(summary)

If you want to see the results from every step in the pipe, you can debug the %>% operator.

debug(`%>%`)

100 %>%         # Poke around the insides of the %>% call
  rnorm() %>%   # More poking
  summary() %>% # Still more poking
  as.character()

undebug(`%>%`)

#4

I like both @mara & @nwerth answers, but I'm going to choose the second one b/c I liked the debug/debug_pipe tutorial. They were both great answers though, thank you very much!