I have some classes which define many properties, only some of which may have a value. The str() function displays all properties, even those of zero-length. Is there a way to only display properties with only a non-zero length?
library(S7)
test_class <- new_class("test_class",
properties = list(
x = class_list,
y = class_character,
z = class_numeric
))
obj <- test_class(z = 1)
str(obj)
#> <test_class>
#> @ x: list()
#> @ y: chr(0)
#> @ z: num 1
# Desired:
#> <test_class>
#> @ z: num 1
Just because the property is empty doesn't mean it doesn't exist, so I think this is the right default display. You can always write your own custom str() method.
I have some classes which define many properties, only some of which may have a value. The
str()
function displays all properties, even those of zero-length. Is there a way to only display properties with only a non-zero length?Created on 2023-11-19 with reprex v2.0.2