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

styling dplyr::case_when() #733

Open
lorenzwalthert opened this issue Feb 15, 2021 · 0 comments
Open

styling dplyr::case_when() #733

lorenzwalthert opened this issue Feb 15, 2021 · 0 comments

Comments

@lorenzwalthert
Copy link
Collaborator

lorenzwalthert commented Feb 15, 2021

Reference: #714, i.e. should be one condition per line. Also note overlap with #258 for ~.

Unfortunately, the structure of the parse table in c(x~y) is not equivalent to c(x = y) so we can't rely on the alignment detection algorithm as is 🤔

styler::cache_deactivate()
#> Deactivated cache.
styler:::create_tree(
  "c(x = y) ;c(x~y)"
)
#>                                                  levelName
#> 1  ROOT (token: short_text [lag_newlines/spaces] {pos_id})
#> 2   ¦--expr: c(x = [0/1] {1}                              
#> 3   ¦   ¦--expr: c [0/0] {3}                              
#> 4   ¦   ¦   °--SYMBOL_FUNCTION_CALL: c [0/0] {2}          
#> 5   ¦   ¦--'(': ( [0/0] {4}                               
#> 6   ¦   ¦--SYMBOL_SUB: x [0/1] {5}                        
#> 7   ¦   ¦--EQ_SUB: = [0/1] {6}                            
#> 8   ¦   ¦--expr: y [0/0] {8}                              
#> 9   ¦   ¦   °--SYMBOL: y [0/0] {7}                        
#> 10  ¦   °--')': ) [0/0] {9}                               
#> 11  ¦--';': ; [0/0] {10}                                  
#> 12  °--expr: c(x~y [0/0] {11}                             
#> 13      ¦--expr: c [0/0] {13}                             
#> 14      ¦   °--SYMBOL_FUNCTION_CALL: c [0/0] {12}         
#> 15      ¦--'(': ( [0/0] {14}                              
#> 16      ¦--expr: x~y [0/0] {15}                           
#> 17      ¦   ¦--expr: x [0/0] {17}                         
#> 18      ¦   ¦   °--SYMBOL: x [0/0] {16}                   
#> 19      ¦   ¦--'~': ~ [0/0] {18}                          
#> 20      ¦   °--expr: y [0/0] {20}                         
#> 21      ¦       °--SYMBOL: y [0/0] {19}                   
#> 22      °--')': ) [0/0] {21}

Created on 2021-02-15 by the reprex package (v1.0.0)

i.e. when at the nest expr / ~ / exp, is_alined is false because that's one level up. Without these two being on the same level, a comparison is very hard. We potentially have to move these expressions one level up with flatten_operators_one(), but potentially only within function calls. This probably implies is_tilde_expr() has to be re-thought too as it is not guaranteed that ~ has position 2 or 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant