Skip to content

Debugging pipped expressions

Chris Baker edited this page Aug 25, 2022 · 3 revisions

The package comes with a bonus feature that makes it easy to view the results of a piped expression. let's say you want to view the results at various points along this pipeline:

library(tidyverse)

starwars %>%
  select(eye_color, films, height) %>%
  filter(eye_color == "blue") %>%
  unnest(films) %>%
  group_by(films) %>%
  summarise(avg_height = mean(height)) %>%
  arrange(avg_height)

Typically you would have to manually insert/remove calls to View() to do that, which can get annoying. hippie provides a function, invoke_view(), that makes it easy to view the intermediate results of any part of a piped-based expression. To use it, first bind an RStudio shortcut to the "Invoke data viewer" action. Then whenever you press the shortcut, hippie will look for the left-most expression that contains a pipe operator and call View() on it.

invoke-view-1-cropped

It doesn't matter if your cursor is in the middle of a function call. As long as hippie can identify a complete expression to run, it will.

invoke-view-2-cropped

Inspired by https://github.com/daranzolin/ViewPipeSteps

Clone this wiki locally