Skip to content

S7 support for tree #76

@ltuijnder

Description

@ltuijnder

Maybe a bit premature as S7 still in active development.

But currently tree inspection with S7 does not work as the S7 machinery is defined with attributes which are hidden by default. But when shown it is too verbose. It would be great if S7 objects could be printed in the tree structure like how currently the print method of S7 works.

Some examples:

library(S7)
library(lobstr)
T <- new_class('T', properties = list(a=class_numeric))
t <- T(1)
tree(t)
#> S3<T/S7_object>
tree(list(t,t,t))
#> <list>
#> ├─S3<T/S7_object>
#> ├─S3<T/S7_object>
#> └─S3<T/S7_object>
tree(t, show_attributes = TRUE)
#> S3<T/S7_object>
#> ├┄attr(,"class")<chr [2]>: "T", "S7_object"
#> ├┄attr(,"S7_class"): function(a)
#> ┊ ├┄attr(,"name"): "T"
#> ┊ ├┄attr(,"parent"): function()
#> ┊ ┊ ├┄attr(,"name"): "S7_object"
#> ┊ ┊ ├┄attr(,"properties"): <list>
#> ┊ ┊ ├┄attr(,"abstract"): FALSE
#> ┊ ┊ ├┄attr(,"constructor"): function()
#> ┊ ┊ ├┄attr(,"validator"): function(self)
#> ┊ ┊ └┄attr(,"class")<chr [2]>: "S7_class", "S7_object"
#> ┊ ├┄attr(,"properties"): <list>
#> ┊ ┊ └─a: S3<S7_property>
#> ┊ ┊   ├─name: "a"
#> ┊ ┊   ├─class: S3<S7_union>
#> ┊ ┊   │ ├─classes: <list>
#> ┊ ┊   │ ┊ ├─S3<S7_base_class>
#> ┊ ┊   │ ┊ │ ├─class: "integer"
#> ┊ ┊   │ ┊ │ ├─constructor_name: "integer"
#> ┊ ┊   │ ┊ │ ├─constructor: function(.data)
#> ┊ ┊   │ ┊ │ ├─validator: function(object)
#> ┊ ┊   │ ┊ │ ├┄attr(,"names")<chr [4]>: "class", "constructor_...", "constructor", "validator"
#> ┊ ┊   │ ┊ │ └┄attr(,"class"): "S7_base_class"
#> ┊ ┊   │ ┊ └─S3<S7_base_class>
#> ┊ ┊   │ ┊   ├─class: "double"
#> ┊ ┊   │ ┊   ├─constructor_name: "double"
#> ┊ ┊   │ ┊   ├─constructor: function(.data)
#> ┊ ┊   │ ┊   ├─validator: function(object)
#> ┊ ┊   │ ┊   ├┄attr(,"names")<chr [4]>: "class", "constructor_...", "constructor", "validator"
#> ┊ ┊   │ ┊   └┄attr(,"class"): "S7_base_class"
#> ┊ ┊   │ ├┄attr(,"names"): "classes"
#> ┊ ┊   │ └┄attr(,"class"): "S7_union"
#> ┊ ┊   ├─getter: <NULL>
#> ┊ ┊   ├─setter: <NULL>
#> ┊ ┊   ├─validator: <NULL>
#> ┊ ┊   ├─default: <NULL>
#> ┊ ┊   ├┄attr(,"names")<chr [6]>: "name", "class", "getter", "setter", "validator", "default"
#> ┊ ┊   └┄attr(,"class"): "S7_property"
#> ┊ ├┄attr(,"abstract"): FALSE
#> ┊ ├┄attr(,"constructor"): function(a)
#> ┊ └┄attr(,"class")<chr [2]>: "S7_class", "S7_object"
#> └┄attr(,"a"): 1

Created on 2025-02-06 with reprex v2.1.1

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