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

Support for dataclasses #300

Open
avhz opened this issue Feb 26, 2025 · 0 comments
Open

Support for dataclasses #300

avhz opened this issue Feb 26, 2025 · 0 comments

Comments

@avhz
Copy link

avhz commented Feb 26, 2025

Would there be any interest in adding dataclasses as a feature, similar to Python's ?

I find that it would help with avoiding initialize boilerplate for the cases where we just want a structured data container.

Currently:

Foo <- R6::R6Class(
  "Foo",
  public = list(
    x = NULL,
    y = NULL,
    z = NULL,
    initialize = function(x, y, z) {
      self$x <- x
      self$y <- y
      self$z <- z
    }
  )
)

foo <- Foo$new(1, 2, 3)

Hopefully:

Foo <- R6::R6DataClass(
  "Foo",
  public = list(
    x = NULL,
    y = NULL,
    z = NULL,
  )
)

foo <- Foo$new(1, 2, 3)

Edit: or possibly just make initialize optional, with a default created for the user that handles their public fields ?

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

1 participant