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

R6 methods don't allow multi-line formals? #1136

Open
MichaelChirico opened this issue Jul 13, 2023 · 7 comments
Open

R6 methods don't allow multi-line formals? #1136

MichaelChirico opened this issue Jul 13, 2023 · 7 comments

Comments

@MichaelChirico
Copy link
Contributor

MichaelChirico commented Jul 13, 2023

The following should be allowed (ref: https://style.tidyverse.org/functions.html#long-lines-1 doesn't mention R6):

R6Class("MyClass",
  public = list(
    param = NULL,
    initialize = function(
        my_long_parameter = getOption("default_long_parameter", 1)) {
      self$param <- my_long_parameter
    }
  )
)

But it's currently re-styled (style_text() output):

R6Class("MyClass",
  public = list(
    param = NULL,
    initialize = function(my_long_parameter = getOption("default_long_parameter", 1)) {
      self$param <- my_long_parameter
    }
  )
)

Which of course creates an over-full line.

@lorenzwalthert

This comment was marked as outdated.

@MichaelChirico

This comment was marked as resolved.

@lorenzwalthert
Copy link
Collaborator

Seems like detection of double indention is based on the absolute indention of the formals, instead of the relative...

@lorenzwalthert
Copy link
Collaborator

This is actually fixed with #1235 I belive, as double indention is not allowed anymore. Can you double check @MichaelChirico?

@MichaelChirico
Copy link
Contributor Author

Unfortunately no, the same bug still applies to the new style guide approach:

styler::style_text(R"(
R6Class("MyClass",
  public = list(
    param = NULL,
    initialize = function(
      my_long_parameter = getOption("default_long_parameter", 1)
    ) {
      self$param <- my_long_parameter
    }
  )
)
)")

gives output

R6Class("MyClass",
  public = list(
    param = NULL,
    initialize = function(my_long_parameter = getOption("default_long_parameter", 1)) {
      self$param <- my_long_parameter
    }
  )
)

@MichaelChirico MichaelChirico changed the title R6 methods don't allow double-indented formals? R6 methods don't allow multi-line formals? Dec 1, 2024
@MichaelChirico
Copy link
Contributor Author

(updated the bug title since it's not about double-indentation per se, but about declaring R6 methods with multi-line formals, under either old or new guide style)

@lorenzwalthert
Copy link
Collaborator

Seems not a problem in unnested case:

styler::style_text('initialize <- function(
    my_long_parameter = getOption("default_long_parameter", 1)) {
  self$param <- my_long_parameter
}')
#> Warning: Could not use `colored = TRUE`, as the package prettycode is not installed.
#> Please install it if you want to see colored output or see
#> `?styler::print.vertical()` for more information.
#> initialize <- function(
#>     my_long_parameter = getOption("default_long_parameter", 1)) {
#>   self$param <- my_long_parameter
#> }

Created on 2024-12-05 with reprex v2.1.0

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

Successfully merging a pull request may close this issue.

2 participants