Skip to content

Add Active bindings section to default print method for R6 class instances #294

@mihaiconstantin

Description

@mihaiconstantin

Consider the following class (i.e., with intentionally confusing member names):

SomeClass <- R6::R6Class("SomeClass",
    private = list(
        .a = NULL,
        .c = NULL
    ),

    public = list(
        e = NULL,

        initialize = function() {
            # ...
        },

        b = function() {
            # ...
        },

        f = function() {
            # ...
        }
    ),

    active = list(
        g = function() {
            # ...
        },

        d = function() {
            # ...
        }
    )
)

Printing the generator yields:

<SomeClass> object generator
  Public:
    e: NULL
    initialize: function () 
    b: function () 
    f: function () 
    clone: function (deep = FALSE) 
  Active bindings:
    g: function () 
    d: function () 
  Private:
    .a: NULL
    .c: NULL
  Parent env: <environment: R_GlobalEnv>
  Locked objects: TRUE
  Locked class: FALSE
  Portable: TRUE

Similarly, printing an instance yields:

<SomeClass>
  Public:
    b: function () 
    clone: function (deep = FALSE) 
    d: active binding
    e: NULL
    f: function () 
    g: active binding
    initialize: function () 
  Private:
    .a: NULL
    .c: NULL

It appears that the members under each access modifier are sorted alphabetically. Would it make sense for the default print method for instances to include an Active bindings section, similar to the object generator? I think this could improve clarity, especially for more complex classes and inheritance chains.

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