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

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

Open
mihaiconstantin opened this issue Oct 22, 2024 · 0 comments

Comments

@mihaiconstantin
Copy link

mihaiconstantin commented Oct 22, 2024

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.

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