-
Notifications
You must be signed in to change notification settings - Fork 232
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
Code formatting in usage section #820
Comments
Yes, this would be great! |
I played around a bit but since I did not know the roxygen code base before, I don't feel confident enough to make a PR with the current code. Maybe @krlmlr do you want to jump in? How should we give the user control about how to exactly style the code? We could let the user specify a styler style guide (defaulting to the tidyverse style guide) or if it should also allow other source code formatter than styler, a function that takes text and returns styled text, defaulting to |
That is too much control — at most, we should have a switch for the old formatting vs the new formatting (one argument per line), and we should only do that if we think there is some strong reason to believe that people might prefer the old formatting. |
Unfortunately the code for usage wrapping is scattered in a few places. Currently, the wrapping is done in https://github.com/klutometis/roxygen/blob/master/R/rd.R#L277-L281, but by that point all we have is a string, so it's too late to implement something more specific. Instead, we'd need to tweak The code is complicated by the fact that the usage statement is not pure R code, but also needs to include Rd formatting for |
This summarizes my struggles well... |
Note that one argument per line is no enforced by styler. What is enforced is that if a call is multi-line and contains named arguments, the line is broken before the first named argument. For details, see tidyverse/style#39. In the style guide, it says in section 2.6:
For this reason, we don't automatically break lines and styler would also be quite a bit more invasive if we'd force line breaks after named arguments and I am not sure we want that. The above paragraph was added in tidyverse/style#52. |
The constraints on formatting usage are different to styling arbitrary code, especially since all the arguments are named. |
Ok, fair point. Once we can make roxygen working with |
I don't think roxygen2 will ever be able to use styler because roxygen2 has to wrap things that are a mix of Rd tags and R code. So here I think we just need to have a heuristic: if they fit, all the arguments go on one line, otherwise, each argument gets its own line. |
Great, thanks for making this work 🎉. |
Rendered help files for multi-line function calls have a
Usage
section that look like the one (taken from fordplyr::join()
):I think developers should potentially have control over how their
Usage
section is printed. In particular, to make it compliant with their style guide of choice. The tidyverse style guide would suggest to put the closing brace on a new line and only put first few unnamed arguments on the first line:I wondered about how that could be implemented in roxygen2 - with or without styler. We have discussed a styler implementation here: r-lib/styler#415.
The text was updated successfully, but these errors were encountered: