-
Notifications
You must be signed in to change notification settings - Fork 71
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
feature request: styling switch
statements
#714
Comments
Potentially also |
Happy to open another issue for this, but first wanted to run by you whether you think Or should it actually be styling styler::style_text(
'starwars %>%
select(name:mass, gender, species) %>%
mutate(
type = case_when(
height > 200 | mass > 200 ~ "large",
species == "Droid" ~ "robot",
TRUE ~ "other"
)
)'
)
#> starwars %>%
#> select(name:mass, gender, species) %>%
#> mutate(
#> type = case_when(
#> height > 200 | mass > 200 ~ "large",
#> species == "Droid" ~ "robot",
#> TRUE ~ "other"
#> )
#> ) Created on 2021-02-15 by the reprex package (v1.0.0) |
Good point. Alignment seems to work with styler::style_text(
'starwars %>%
select(name:mass, gender, species) %>%
mutate(
type = c(
a = "large",
bvv = "robot",
naot = "other"
)
)'
)
#> starwars %>%
#> select(name:mass, gender, species) %>%
#> mutate(
#> type = c(
#> a = "large",
#> bvv = "robot",
#> naot = "other"
#> )
#> ) Created on 2021-02-15 by the reprex package (v1.0.0) I think we should first implement alignment detection for |
Not sure if this deserves a separate issue. I wanted to check with you first about what you think about this, since I couldn't find any styling guidelines for this context. Do you think the following styler::style_text(
'switch(type,
"x" = "1",
"y" = ifelse(cond1,
"2",
ifelse(cond2, "3", "4")
),
"z" = "5"
)'
)
#> switch(type,
#> "x" = "1",
#> "y" = ifelse(cond1,
#> "2",
#> ifelse(cond2, "3", "4")
#> ),
#> "z" = "5"
#> ) Created on 2021-07-01 by the reprex package (v2.0.0) should instead be styled to? #> switch(type,
#> "x" = "1",
#> "y" = ifelse(cond1,
#> "2",
#> ifelse(cond2, "3", "4")
#> ),
#> "z" = "5"
#> ) That is, none of the |
I think the normal indention rules should apply, so I think current output is as desired. |
The
tidyverse
style guide states-styler
currently produces the following output:Created on 2021-01-13 by the reprex package (v0.3.0)
But I'd have expected it to return:
The more conditions there are, the more useful this will become.
Session info
The text was updated successfully, but these errors were encountered: