r-lib / styler

Non-invasive pretty printing of R code
https://styler.r-lib.org
Other
730 stars 71 forks source link

Avoid add new line before closing bracket #1226

Closed elgabbas closed 1 month ago

elgabbas commented 2 months ago

I would like to disable styler of adding a new line before the closing bracket of a long function call

Here is an example

example <- 'c(
"Mazda RX4", "Mazda RX4 Wag", "Datsun 710", "Hornet 4 Drive", 
"Hornet Sportabout", "Valiant", "Duster 360", 
"Merc 240D", "Merc 230",  "Merc 280")'

styler::style_text(example)

The output

c(
  "Mazda RX4", "Mazda RX4 Wag", "Datsun 710", "Hornet 4 Drive",
  "Hornet Sportabout", "Valiant", "Duster 360",
  "Merc 240D", "Merc 230", "Merc 280"
)

Is it possible to get the following instead?

c(
  "Mazda RX4", "Mazda RX4 Wag", "Datsun 710", "Hornet 4 Drive",
  "Hornet Sportabout", "Valiant", "Duster 360",
  "Merc 240D", "Merc 230", "Merc 280")

Thanks

lorenzwalthert commented 2 months ago

Not with minimal effort, as this is not in line with the tidyverse style guide. You would have to modify the transformer rules that create a line break as described per the vignettes in this package.