-
Notifications
You must be signed in to change notification settings - Fork 111
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
Line breaks in function calls with named arguments #39
Comments
I don't think your example is quite right. I think the question has to involve named arguments. switch(on_same_line,
option_a = next_line,
option_b = another_new_line
) And I think the principle is that it's ok to put all the un-named arguments on the first line, if they fit. If they don't fit on one line, then they should be spread over multiple lines. I think this convention is nice for map(x, f,
extra_argument_a = 10,
extra_argument_b = NA
) If no arguments are named, and it doesn't fit on one line.then each argument always gets its own line. |
Ok, thanks for the clarification. cc: @krlmlr |
Relevant links with a draft and another corner case: |
This version handles line breaks in function calls according to tidyverse/style#39.
* styling with strict = FALSE and scope = "tokens" * styling with styler#318. strict = TRUE, scope = "tokens"). This version handles line breaks in function calls according to tidyverse/style#39.
To close this issue, can we include such a paragraph in the style guide that describes the principle outlined above? I can get us started with PR if @hadley does not want to do it himself. |
The principle should mention something about unnamed arguments being special - you only omit the names of arguments when they are used sufficiently commonly (i.e. with almost every invocation of that function) that you can assume most readers will know know what they are. |
In the styler project, we came across the question whether the rule to
applies to all functions, or whether
switch()
,ifelse()
and friends are an exception to it In other words, whetherIs preferred over
Another (potential) candidate is
case_when()
.Reference: krlmlr/rlang#1 (comment), r-lib/styler#152.
The text was updated successfully, but these errors were encountered: