Skip to content

Support for dataclassesΒ #300

@avhz

Description

@avhz

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions