-
Notifications
You must be signed in to change notification settings - Fork 73
Named arguments not forced to one per line? #926
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
A somewhat related situation is: poslt <- as.POSIXlt("2010-02-03 13:45:59", tz = "GMT", format = "%Y-%m-%d %H:%M:%S") which because is >80 characters wide, I'd expect to get restyled as: poslt <- as.POSIXlt(
"2010-02-03 13:45:59",
tz = "GMT",
format = "%Y-%m-%d %H:%M:%S"
)
# or from a strict reading of the style guide
poslt <- as.POSIXlt("2010-02-03 13:45:59",
tz = "GMT",
format = "%Y-%m-%d %H:%M:%S"
)
|
Another similar example is: poslt <- as.POSIXlt(c("2010-02-14 01:59:59", "2010-02-15 01:59:59", "2010-02-16
01:59:59"), tz = "UTC", format = "%Y-%m-%d %H:%M:%S") which definitely has to become poslt <- as.POSIXlt(
c("2010-02-14 01:59:59", "2010-02-15 01:59:59", "2010-02-16 01:59:59"),
tz = "UTC",
format = "%Y-%m-%d %H:%M:%S"
) since the If I add a couple more date-times to get this: poslt <- as.POSIXlt(c("2010-02-14 01:59:59", "2010-02-15 01:59:59", "2010-02-16 01:59:59",
"2010-02-16 01:59:59", "2010-02-16 01:59:59"), tz = "UTC", format = "%Y-%m-%d %H:%M:%S") Then restyling gives me: poslt <- as.POSIXlt(c(
"2010-02-14 01:59:59", "2010-02-15 01:59:59", "2010-02-16 01:59:59",
"2010-02-16 01:59:59", "2010-02-16 01:59:59"
), tz = "UTC", format = "%Y-%m-%d %H:%M:%S") whereas I would prefer: poslt <- as.POSIXlt(
c(
"2010-02-14 01:59:59",
"2010-02-15 01:59:59",
"2010-02-16 01:59:59",
"2010-02-16 01:59:59",
"2010-02-16 01:59:59"
),
tz = "UTC",
format = "%Y-%m-%d %H:%M:%S"
) |
doesn't this apply as a reason not to always restyle named arguments?
this for example helps plot() calls from taking up a lot of vertical real estate by e.g. allowing xlim=, xlab=, xaxt=, las=, to be on the same line if they fit. |
I'm pretty sure I meant that advice to only apply to unnamed arguments. |
Thanks @hadley. I agree on your first post. I was aware of this, but given other more urgent issues and my time constraints, it's not implemented yet. On the other posts: They would in my opinion be resolved if the rule for 80 characters was implemented, which is the most upvoted unclosed issue that is quite complex to implement I anticipate: #247. I have not started with it yet and don't think I will soon. |
Ah ok, makes sense. The other thing that I've been wondering about is maybe if it would make sense to supply styler with a few manual formatters that would (e.g.) allow to you toggle between all arguments on one line to each argument on its own line. Obviously that wouldn't help with restyling a complete package, but by binding it to a keyboard shortcut, it would make it very easy to restyle as needed. |
We aimed for a non-invasive formatter when building the package and allowed many configuration options, i.e. if you check the tidyverse_style(
scope = "tokens",
strict = TRUE,
indent_by = 2,
start_comments_with_one_space = FALSE,
reindention = tidyverse_reindention(),
math_token_spacing = tidyverse_math_token_spacing()
) More prominent styling aspects have their own argument, the rest is grouped into the residual Hence, the most natural extension would just be to add My main concern with these special formatters you suggested is that they are a bit of a one-way street, in particular for the case outlined in this issue, as long as there is no character limit implemented (e.g. with #247). I don't think anyone would want to force putting all arguments on the same line. Hence, I'd prefer to just implement another argument for |
What I was thinking has been implemented in https://github.com/lionel-/codegrip/, so I'm going to close this issue. |
Ok, good to know. But since we want to be style guide compliant, I think we’ll eventually also implement that functionality. |
I had expected
to be restyled to
Since https://style.tidyverse.org/syntax.html#long-lines says "use one line each for the function name, each argument, and the closing )".
This rule should only apply to named arguments, and I'd expect the following code to be left as is:
(I'm spotting these cases because I've started restyling lubridate, which has a mismash of code styles from years of development. styler has made a big improvement and I really appreciate all the work you have put in this package 😄)
The text was updated successfully, but these errors were encountered: