You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue is that [[<- doesn’t interact with any parts of S7 in this case, so it doesn’t trigger validation.
For example, in the snippet above, class(x) is c("list_derived_class", "list", "S7_object"), and the [[<- method for list is the one being invoked.
One workaround is to define a [[<- method on the S7 class that explicitly calls validate().
In the example method below, I’m using NextMethod() to delegate to the [[<- method for list. Note that using NextMethod() with S7 is technically “off-label” usage; the ultimate intention is for S7_data() and S7::super() to address this need. However, S7_data() needs a little more work, and NextMethod() can be a reliable solution in the interim.
Thank you, @t-kalinowski for the nice explanation and the workaround.
It would be very nice if when the S7_base_class would provide a wrapper around "list" with validate() call in place - e.g. a S7_list which overwrites [[<-
Related to #413
The validator is also not triggered when
new_class
derives from a base type as showcased in this example e.g.:This is rather counter intuitive behavior when deriving from a class.
One suggestion would be that
S7_base_class
provided by e.g.class_list
would overwrite the base setters installing a hook to trigger the validator.The text was updated successfully, but these errors were encountered: