Closed t-kalinowski closed 2 weeks ago
To me, the question is more about what constitutes the structure, str()
, of the object? Are dynamic properties part of the structure? Users will not care about whether a property is dynamic or not; they just see them as properties, so I think the answer is "yes." It would be surprising for a property not to show up in str()
.
This reminds of the deprecated property case though. It would be annoying to get a warning every time the object is printed, so there would need to be a custom str()
method. Or, we add formal support for property deprecation that effectively hides them.
Possibly both are right: str() should mention properties by default. OTOH, its S7_object method get an option to suppress them. Then the print() method may in some cases use that suppression option ..
I think we can default to calling print()
with suppressWarnings()
, to handle the deprecated property case.
For the deprecated property case, if class authors truly want to deprecate a property, they'll also want to implement a print()
method that doesn't show the deprecated property. Alternatively, they can include conditional logic in the getter to suppress warnings when called from print
, like this:
getter = function(self) {
warn <- TRUE
for (cl in sys.calls()) {
if (cl[[1]] == quote(print.S7_object)) {
warn <- FALSE
break
}
}
if (warn) {
warning("@foo is deprecated")
}
self@newfoo
}
We probably should not call
getter()
from the print method, as it might be a potentially expensive operation.