boomer
boomer copied to clipboard
Indentation for long pipe chains
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)?
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.
What would be the default for max_indent
?
Could be Inf
but right now I feel 10 (20 chars) might be good. We might need to play around with it.