Newline after multiline arguments?
This looks fairly awkward to me:
styler::style_text("
list(
c(
a
), c(
b
)
)
")
#> list(
#> c(
#> a
#> ), c(
#> b
#> )
#> )
Created on 2023-06-15 with reprex v2.0.2
I think there should be a newline after ), . Is there a rule in the style guide? Should there be one?
@MichaelChirico suggests that enforcing the newline creates wasted space. While true, I also find the comma between ) and c( difficult to spot, and I'm happy to trade the extra lines for readability here.
Downstream: https://github.com/r-lib/styler/issues/1133 (which also suggests to discuss here first).
This is the relevant section:
https://style.tidyverse.org/syntax.html#long-lines
Is your example really representative? In particular the second argument being unnamed. I find that often in practice examples like yours can be reflowed with explicit arguments instead:
# foo = function(descriptive_name1, descriptive_name2)
foo(
c(
a
), c(
b
)
)
foo(
descriptive_name1 = c(
a
),
descriptive_name2 = c(
b
)
)
It might help to share some specific package code you've come across that'd be affected by the rule here.
If a function call is too long to fit on a single line, use one line each for the function name, each argument, and the closing ).
Does the ), c( violate this very rule because parts of two arguments are on the same line?
Occasionally, I create unnamed lists of vectors, with foo === list in your example. (+1 for getting === into base R.)
Yes, there definitely should be a new line there, yielding:
list(
c(
a
),
c(
b
)
)
(and this is what codegrip generates)
I agree that this violates the "no more than one argument per line" rule.
So I think this is covered by the style guide (or at least is sufficiently esoteric we don't need to explicit mention it)