boomer icon indicating copy to clipboard operation
boomer copied to clipboard

Indentation for long pipe chains

Open krlmlr opened this issue 3 years ago • 3 comments

library(magrittr)

piped <- function(x) {
  x %>% 
    identity() %>% 
    identity() %>% 
    identity()
}

piped <- boomer::rig(piped)

piped(3)
#> 👇 piped
#> 💣 %>%
#> · 💣 identity
#> · · 💣 identity
#> · · · 💣 identity
#> · · · 💥 identity(.)
#> · · · [1] 3
#> · · · 
#> · · 💥 identity(.)
#> · · [1] 3
#> · · 
#> · 💥 identity(.)
#> · [1] 3
#> · 
#> 💥 x %>%  identity() %>%  identity() %>%  identity()
#> [1] 3
#> 
#> 👆 piped
#> [1] 3

Created on 2021-06-17 by the reprex package (v2.0.0)

Is there a way to flatten these? Maybe after reaching a certain depth we could switch to two-digit numbers (and add an extra level only if another function is called)?

krlmlr avatar Jun 17 '21 03:06 krlmlr

It we give a special treatment to %>% we'll still have the same issue with the native pipe and I'm not sure if we could handle it then, the native pipe not being a real op (maybe with some srcref magic).

Maybe we could have a max_indent option, if set to zero, we'd only print "1>" etc, otherwise behavior would be more like what you suggested, but for every function.

moodymudskipper avatar Jun 17 '21 06:06 moodymudskipper

What would be the default for max_indent ?

krlmlr avatar Jun 18 '21 02:06 krlmlr

Could be Inf but right now I feel 10 (20 chars) might be good. We might need to play around with it.

moodymudskipper avatar Jun 18 '21 07:06 moodymudskipper