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

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(`%>%`)
5 Likes