Skip to content

Allowing call-like function definitions if delineated properly #173

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

Closed
MichaelChirico opened this issue Aug 4, 2021 · 2 comments
Closed

Comments

@MichaelChirico
Copy link
Collaborator

Filed first as r-lib/styler#829, but in writing that I realized the style guide itself could weigh in here as well.

Currently in the style guide we have (https://style.tidyverse.org/functions.html#long-lines-1):

# Bad
long_function_name <- function(a = "a long argument",
  b = "another argument",
  c = "another long argument") {
  # Here it's hard to spot where the definition ends and the
  # code begins
}

I basically see the point about c = having the same indentation as the function body and thus needing to scan for { at the end of a line to find the start/end of the definition.

However I think this is nicely avoided by just dropping ) { to the next line:

long_function_name <- function(
  a = "a long argument",
  b = "another argument",
  c = "another long argument"
) {
  # function body
}

I would prefer to allow this latter usage, but either weigh it would be helpful for the style guide to be explicit.

@hadley
Copy link
Member

hadley commented Aug 23, 2021

@MichaelChirico how do you feel about the proposal in #174:

long_function_name <- function(
    a = "a long argument",
    b = "another argument",
    c = "another long argument") {
  # As usual code is indented by two spaces.
}

The main difference is that we double indent the argument list and keep ) { on the same line — this matches Google's advice for C++ and was the consensus vote amongst the tidyverse team.

@hadley
Copy link
Member

hadley commented Sep 30, 2021

Closed by #174 (I know this isn't exactly what you were looking for but it's the closest I could get and still maintain rough consensus)

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

2 participants