-
Notifications
You must be signed in to change notification settings - Fork 73
Feature Request: Add new line after comma following function call #993
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
Comments
The code in your first code block is styled to with fun_call(
another_function_call(), yet_another_function_call_with_arg(x), and_another_call()
)
|
The first block with all the function calls in one line is not readable. The second block is readable for the same reason tidyverse style generally places new lines after pipes. I'm just trying to use targets instead of pipes because my workflow takes a long time to execute and I want to ensure reproducibility of my output. For me In short: I think 99% of humans would prefer to read the following: fun_call(
another_function_call(),
yet_another_function_call_with_arg(x),
and_another_call()
) To make this more concrete, let me say that in my case Maybe I am misunderstanding. Are you saying maybe I need to be using the development version? Alternatively, is it easy to make a custom rule to do that (and maybe only that) in the interim? It makes sense to me that this is harder than it looks because if there are two or more arguments with a comma, I don't want to insert a split if all arguments aren't function calls. foo(
bar(x, y, z),
baz(
x,
bop()
)
) I made an attempt to accomplish the singular rule (so I could get on with fleshing out my paper) by copying a similar sounding rule for line breaks and changing it for |
The original project motto was "non-invasive pretty printing". So, styler will not attempt to alter the perceived intent of the formatting. A quick hack to get the desired result could be to replace all instances of, say I haven't found anything on function calls in https://style.tidyverse.org, what am I missing? I agree that multiple arguments on the same line may be confusing. We could consider being more invasive with call(with, all, arguments, in_(one, line))
call(
with,
all,
arguments,
on = c(separate, lines)
) |
FWIW the relevant style guide section starts here https://style.tidyverse.org/syntax.html#long-lines |
No.
Styler does not support breaking lines at a certain character yet, see #247.
Adding a line break after each argument if a function call is multi-line is a duplicate of #926.
Yes, see #926. Also see https://github.com/gadenbuie/grkstyle. |
I really appreciate all the suggestions I have received in this thread. I think the suggestion from @krlmlr to just do some ad-hoc preprocessing before sending code to |
I may be missing something since I just started using styler, but I don't understand why styler with the defaults thinks things like the following are readable code:
fun_call( another_function_call(), yet_another_function_call_with_arg(x), and_another_call())
I think it is easier to read code when there are new lines after each of these internal function calls followed by a comma.
fun_call( another_function_call(), yet_another_function_call_with_arg(x), and_another_call())
The above is a lot more readable.
Note that in my use case I am trying to automatically format code not in a file but as it is returned from R.
styler
works pretty well otherwise helping me write papers where I show R code in a package in a fully reproducible automatic manner, but wide formatted stuff like the above just isn't something I want to place in a paper.So, I guess I'm requesting an additional
line_break
rule. Maybe call itset_line_break_after_comma_following_nested_function_call
?The text was updated successfully, but these errors were encountered: