Skip to content

feature request: removing empty lines in function calls #627

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

Closed
IndrajeetPatil opened this issue Apr 8, 2020 · 13 comments · Fixed by #629 or #645
Closed

feature request: removing empty lines in function calls #627

IndrajeetPatil opened this issue Apr 8, 2020 · 13 comments · Fixed by #629 or #645

Comments

@IndrajeetPatil
Copy link
Collaborator

Not sure what the tidyverse style guide says here, but sometimes I want to remove some function arguments I had specified at multiple places in a script and then styling the file doesn't remove those empty lines.

Is this something that styler should be doing?

  • Observed:
styler::style_text("
                   broom::tidy(
                   x = stats::lm(formula = wt ~ mpg, data = mtcars),
                   
                   conf.int = TRUE,
                   conf.level = 0.99
                   )
                   ")
#> 
#> broom::tidy(
#>   x = stats::lm(formula = wt ~ mpg, data = mtcars),
#> 
#>   conf.int = TRUE,
#>   conf.level = 0.99
#> )

Created on 2020-04-08 by the reprex package (v0.3.0.9001)

Session info
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                                             
#>  version  R Under development (unstable) (2020-02-28 r77874)
#>  os       Windows 10 x64                                    
#>  system   x86_64, mingw32                                   
#>  ui       RTerm                                             
#>  language (EN)                                              
#>  collate  English_United States.1252                        
#>  ctype    English_United States.1252                        
#>  tz       Europe/Berlin                                     
#>  date     2020-04-08                                        
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version    date       lib source                           
#>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 4.0.0)                   
#>  backports     1.1.6      2020-04-05 [1] CRAN (R 4.0.0)                   
#>  cli           2.0.2      2020-02-28 [1] CRAN (R 4.0.0)                   
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 4.0.0)                   
#>  digest        0.6.25     2020-02-23 [1] CRAN (R 4.0.0)                   
#>  ellipsis      0.3.0      2019-09-20 [1] CRAN (R 4.0.0)                   
#>  evaluate      0.14       2019-05-28 [1] CRAN (R 4.0.0)                   
#>  fansi         0.4.1      2020-01-08 [1] CRAN (R 4.0.0)                   
#>  fs            1.4.1      2020-04-04 [1] CRAN (R 4.0.0)                   
#>  glue          1.4.0      2020-04-03 [1] CRAN (R 4.0.0)                   
#>  highr         0.8        2019-03-20 [1] CRAN (R 4.0.0)                   
#>  htmltools     0.4.0      2019-10-04 [1] CRAN (R 4.0.0)                   
#>  knitr         1.28       2020-02-06 [1] CRAN (R 4.0.0)                   
#>  lifecycle     0.2.0.9000 2020-03-16 [1] Github (r-lib/lifecycle@355dcba) 
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 4.0.0)                   
#>  pillar        1.4.3      2019-12-20 [1] CRAN (R 4.0.0)                   
#>  pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.0.0)                   
#>  prettycode    1.1.0      2019-12-16 [1] CRAN (R 4.0.0)                   
#>  purrr         0.3.3      2019-10-18 [1] CRAN (R 4.0.0)                   
#>  R.cache       0.14.0     2019-12-06 [1] CRAN (R 4.0.0)                   
#>  R.methodsS3   1.8.0      2020-02-14 [1] CRAN (R 4.0.0)                   
#>  R.oo          1.23.0     2019-11-03 [1] CRAN (R 4.0.0)                   
#>  R.utils       2.9.2      2019-12-08 [1] CRAN (R 4.0.0)                   
#>  Rcpp          1.0.4      2020-03-17 [1] CRAN (R 4.0.0)                   
#>  reprex        0.3.0.9001 2020-03-25 [1] Github (tidyverse/reprex@a019cc4)
#>  rlang         0.4.5      2020-03-01 [1] CRAN (R 4.0.0)                   
#>  rmarkdown     2.1        2020-01-20 [1] CRAN (R 4.0.0)                   
#>  rstudioapi    0.11       2020-02-07 [1] CRAN (R 4.0.0)                   
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 4.0.0)                   
#>  stringi       1.4.6      2020-02-17 [1] CRAN (R 4.0.0)                   
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 4.0.0)                   
#>  styler        1.3.2      2020-02-23 [1] CRAN (R 4.0.0)                   
#>  tibble        3.0.0      2020-03-30 [1] CRAN (R 4.0.0)                   
#>  vctrs         0.2.4      2020-03-10 [1] CRAN (R 4.0.0)                   
#>  withr         2.1.2      2018-03-15 [1] CRAN (R 4.0.0)                   
#>  xfun          0.12       2020-01-13 [1] CRAN (R 4.0.0)                   
#>  yaml          2.2.1      2020-02-01 [1] CRAN (R 4.0.0)                   
#> 
#> [1] C:/Users/inp099/Documents/R/win-library/4.0
#> [2] C:/Program Files/R/R-devel/library
  • Expected:
#> 
#> broom::tidy(
#>   x = stats::lm(formula = wt ~ mpg, data = mtcars),
#>   conf.int = TRUE,
#>   conf.level = 0.99
#> )
@lorenzwalthert
Copy link
Collaborator

lorenzwalthert commented Apr 8, 2020

I think this a reasonable suggestion. We can leave as is for strict = FALSE.

@IndrajeetPatil
Copy link
Collaborator Author

Do you think the same can also be extended from function calls to the entire code?

For example, here is a simple example where I think styler can remove the unnecessary empty line in the code block:

styler::style_text("
mtcars %>%
  
  dplyr::select(mt, mpg)
")
#> 
#> mtcars %>%
#> 
#>   dplyr::select(mt, mpg)

Created on 2020-06-05 by the reprex package (v0.3.0)

@lorenzwalthert
Copy link
Collaborator

I agree. Wanna make a PR? You'd probably need to tweak add_line_break_after_pipe().

@IndrajeetPatil
Copy link
Collaborator Author

Sorry, unfortunately, I don't know enough about styler's internal code to be of any help in making a PR. :(

@lorenzwalthert
Copy link
Collaborator

lorenzwalthert commented Jun 5, 2020 via email

@lorenzwalthert
Copy link
Collaborator

Related: #632

lorenzwalthert added a commit that referenced this issue Jun 6, 2020
- No more than one line break between pipes (#627).
@lorenzwalthert
Copy link
Collaborator

@IndrajeetPatil wanna have a look at #645 and try it out. It's merged into master.

@IndrajeetPatil
Copy link
Collaborator Author

Das ist perfekt! :)

styler::style_text("
mtcars %>%
  
  dplyr::select(mt, mpg)
")
#> 
#> mtcars %>%
#>   dplyr::select(mt, mpg)

Thanks for implementing these feature requests.

@IndrajeetPatil
Copy link
Collaborator Author

@lorenzwalthert For some reason, this doesn't work with the %<>% operator from magrittr:

    styler::style_text("
    mtcars %<>%
      
      dplyr::select(mt, mpg)
    ")
    #> 
    #> mtcars %<>%
    #> 
    #>   dplyr::select(mt, mpg)

Created on 2020-10-01 by the reprex package (v0.3.0.9001)

@lorenzwalthert
Copy link
Collaborator

Because it was not implemented for any infix operator, just for %>%.

@lorenzwalthert lorenzwalthert reopened this Oct 1, 2020
@IndrajeetPatil
Copy link
Collaborator Author

I am not sure if this should be a separate issue, but it's very related, so I will also post it here:

I'd expect the following

styler::style_text("df <-

                   mtcars %>%
                   
                   dplyr::filter(am == 0)")
#> df <-
#> 
#>   mtcars %>%
#>   dplyr::filter(am == 0)

Created on 2020-10-21 by the reprex package (v0.3.0.9001)

to be instead styled as-

#> df <-
#>   mtcars %>%
#>   dplyr::filter(am == 0)

Does that make sense?

@lorenzwalthert
Copy link
Collaborator

It does make sense yes but it's technically a different thing (line breaks in assignments), so please file a separate issue.

@lorenzwalthert
Copy link
Collaborator

Thanks @IndrajeetPatil.

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