tidyverse / style

The tidyverse style guide for R code
https://style.tidyverse.org
Other
292 stars 100 forks source link

Multiline function declarations #215

Open krlmlr opened 1 month ago

krlmlr commented 1 month ago

There's a disagreement between codegrip and the style guide (and styler). I can't find the original discussion but wanted to raise this here.

@lionel- considers the codegrip style to be the better one, I agree. What do you think, @hadley and @MichaelChirico?

codegrip

mcmc_derive_fun <- function(
    object,
    new_data = data_set(object),
    new_expr = NULL,
    ...
) {

Style guide

mcmc_derive_fun <- function(
    object,
    new_data = data_set(object),
    new_expr = NULL,
    ...) {
hadley commented 1 month ago

We should update the style guide IMO

MichaelChirico commented 1 month ago

I'm partial to the codegrip approach. FWIW I know this point came up in the original discussion.

lionel- commented 3 weeks ago

Another thing to change in the style guide is double indent of arguments, it should be single indent (same as body).

I'm sorry to have advocated so much for the google style at the time, only to then change my mind :-)

After having worked with typescript and rust @DavisVaughan and I now think we should be consistent with the widespread style habits in these communities.

DavisVaughan commented 2 weeks ago

i.e. in the Double-indent section here https://style.tidyverse.org/functions.html#long-lines-1, when we also update recommendations for placement of ) {

it should be this:

mcmc_derive_fun <- function(
  object,
  new_data = data_set(object),
  new_expr = NULL,
  ...
) {
  body
}

not

mcmc_derive_fun <- function(
    object,
    new_data = data_set(object),
    new_expr = NULL,
    ...
) {
  body
}

@lionel- codegrip needs an update to fix that too right? I think it currently does the double indent, opened https://github.com/lionel-/codegrip/issues/20