Skip to content
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

Question: How to customise styler so that line break before ) { in function definitions? #1130

Closed
rkrug opened this issue Jun 11, 2023 · 10 comments

Comments

@rkrug
Copy link

rkrug commented Jun 11, 2023

Assume I have the following function definition, formatted in VS Code using the tidy verse styler:

addAttributes <- function(
    x,
    nm,
    puml) {
    cat(TRUE)
}

I would prefer to have the following:

addAttributes <- function(
    x,
    nm,
    puml
) {
    cat(TRUE)
}

How can I modify the tidyverse_style() so that it is formatted as I would like to have it, i.e. have a line break in front of the ) {, unless it is in the same line as the ( in the function definition?

Thanks,

Rainer

@lorenzwalthert
Copy link
Collaborator

I can’t tell you on top of my head but you should find the answer if you look at the docs. In particular https://styler.r-lib.org/articles/customizing_styler.html

@krlmlr
Copy link
Member

krlmlr commented Jul 22, 2023

I recently tried this on this particular use case. I ended up with the following script: https://rpubs.com/krlmlr/styler-resp .

I do prefer

x <- function(
    a,
    b
) {
}

over

x <- function(
    a,
    b) {
}

. This is also what the codegrip package emits -- a huge time saver. However, https://style.tidyverse.org/functions.html#long-lines-1 mandates the last form. This is unfortunate.

Because styler is about non-invasive pretty-printing, we should support keeping the first form. @lorenzwalthert: How do you feel about this, at least for strict = FALSE ?

Upstream: tidyverse/style#202.

@lorenzwalthert
Copy link
Collaborator

a huge time saver.

Can you elaborate why? Maybe time is also an argument in the tidyverse style guide?

I think we should implement the style guide but for strict = FALSE I am open.

@krlmlr
Copy link
Member

krlmlr commented Aug 14, 2023

I chose to tweak codegrip instead: https://github.com/lionel-/codegrip/pull/16.

@lorenzwalthert
Copy link
Collaborator

Ok, also fine.

@rkrug
Copy link
Author

rkrug commented Nov 30, 2023

But this does not help me as a lonely VSCode user...

@lorenzwalthert
Copy link
Collaborator

Sorry I can't support this in {styler}. It's not compliant with the tidyverse style guide...

@rkrug
Copy link
Author

rkrug commented Nov 30, 2023

I understand - but Is there any styler option which makes this possible, as it states "styler formats your code according to the tidyverse style guide (or your custom style guide)" on https://styler.r-lib.org?

@lorenzwalthert
Copy link
Collaborator

Not with tidyverse_style(). The part of {styler} that makes it possible is the infrastructure to run you style guide. But you have to provide your own style guide. There is no option in tidyverse_style() for it.

@krlmlr
Copy link
Member

krlmlr commented Dec 2, 2023

@rkrug: See #1130 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants