-
Notifications
You must be signed in to change notification settings - Fork 37
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
S7 with varargs #515
Comments
Thanks for raising this; it's an idea worth discussing. With respect to the rvest use case, while I have never used rvest, it seems reasonable to group non-standard elements into their own list. The code becomes explicit about what is special about the field. Instead of Another way to conceptualize this field structure is as a list (just as it was using S3), but one where a subset of its elements are guaranteed to be present (and perhaps of a certain type). That could easily be done by extending |
Apologies, but do you mind further explaining how you could extend |
If you know in advance what the elements will be, you should make them fields. If you don't know what they will be, you should just dump them in a list. In that case, you can't do type checking because you don't know what they are. |
That makes sense, fair enough. Do you think there's any point in automatically handling dots by tweaking |
I don't think so, since it's easy enough to do in a wrapper. |
Fair enough, I'll close the issue then. Thank you! |
When converting some rvest S3 classes to S7 I happened upon
rvest_field
which has an interesting S3 implementation using...
:I noted that in the rvest implementation there was only one use case of the dots, and that was to pass a specific value called
options
so I opted to make that an optional property of the S7rvest_field
, and removed the dots in its construction. That led me to question how one would mimic the original behaviour as closely as possible using S7 though. The first thought I had was to take the dots and stick them into a property:But now you obviously have to do
test(10, x=1)@varargs$x
which isn't very pretty--and you also lose validation for the fauxx
"property" which defeats a lot of the benefits of S7 I think (but nominally solves the problem). Dealing with the first issue is easy (see below for a very rough implementation), but I don't know what an nice way of solving the latter would be. Maybe pass a list with arguments and attached properties liketemp(x = "hi", y = 2, list(x = class_character, y = new_property(class_numeric, getter = function(self) self@y, setter = NULL)))
and then parse the list on construction? And then instead of making someone deal with all that everytime they want to create a S7 object with the dots, expose a varargs class which does this and make objects which want to have variable properties inherit from it?
I also don't know how pertinent this is, but I think it would be cool to be able to create S7 objects with variable properties proper, instead of looking up arguments in an list. I'd be happy to work on this if it is useful/feasible.
The text was updated successfully, but these errors were encountered: