Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indentation for long pipe chains #45

Open
krlmlr opened this issue Jun 17, 2021 · 3 comments
Open

Indentation for long pipe chains #45

krlmlr opened this issue Jun 17, 2021 · 3 comments
Milestone

Comments

@krlmlr
Copy link
Collaborator

krlmlr commented Jun 17, 2021

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)?

@moodymudskipper
Copy link
Owner

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.

@krlmlr
Copy link
Collaborator Author

krlmlr commented Jun 18, 2021

What would be the default for max_indent ?

@moodymudskipper
Copy link
Owner

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

@moodymudskipper moodymudskipper added this to the 0.2 milestone Jun 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants