-
Notifications
You must be signed in to change notification settings - Fork 20
Internal settings container: Proof of concept #465
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
Internal settings container: Proof of concept #465
Conversation
|
I have to admit I really like the freedom and flexibility of the functions with the long argument lists where we just can shove anything in and out. But I also agree that containerization will probably make the code more readable. I'm not convinced, though, that using S4 classes is a good idea. First, it necessitates loading one more package (even if it is a base package that is loaded by default in most R configs). Also the automatic sanity checking is "free" but comes at a computational cost, especially if the checks are triggered often. So I wonder whether there is maybe some middle ground between the current freedom and the strict S4 approach. |
|
Oh yeah, I'm absolutely not wedded to S4. Happy to use any container structure. I do see the appeal of long lists of arguments, but IMHO this already has a big scope and we may introduce more things for other types, so maintainability and clarity are pretty big priorities at this stage |
|
Yes, I do see potential in making things more explicit and wrapped up in one place. One thing I'm not sure about is how the container structure helps with tracking the evolution from defaults plus user settings to sanitized settings to type-specific settings. Would you keep multiple copies of the entire list rather than copies of individual variables? |
|
Good question, and I'll have to think about that. One option is that a lot of checks we want could simply be This is the kind of thing that is likely to become clearer for me when I give this a "real" try. |
|
I'm not sure whether the Off the top of my head, I would probably collect the user input in a plain list first and at that point run some sanity checks with rather explicit warning/error messages etc. because that might be helpful for the user. And that list might then get stored along with some subsequent version(s) of it. But I haven't played any of this through... |
|
Just catching up here after work. I like the idea and can see how a more structured OOP system like S4 would gives us a lot of control... but am also weary of introducing this as a dependency and have yet to use it for any of my other packages. Honestly, it sounds like something that we should discuss on a call if you are both up for it? I'll send an email to propose. |
Really, the vault could just be a named list... Happy to talk when I come back home from this conference. |
|
Closing in favor of the more fleshed out example here: Note that I have not done this other people to commit anyone to this. Still very much up for debate whether we eant to do this. I just thought it would be useful to actually see what the core function might look like after simplification/modularization/centralization. |
Some challenges we face in
tinyplotlist2env, but also because overwrite a lot of variables, which makes user input unavailable, and forces us into tricks likexlim_user.type_*()functions, which complicates things like labelling (see recent discussion with @zeileis on type-specific labels).Potential solution
settingsthat holds all user input, state variables, and computed parameters.settings.settingsas input, it callssettings_to_environment()at the top.settingsas input and wants to modify something, it assigns explicitly the new values just beforereturn(settings).return()statement.initialize()to perform some sanity checks and assertions on user input automatically, without polluting the main code.tinytableand `marginaleffects, and it has worked out super nicely. The code is much cleaner now.Proof of concept
This is just a proof of concept PR, with tiny subset of parameters. We have a simple
tinyplot_settingsobject, that we initialize with some user input. Then, we pass those settings off tosanitize_type, which modifies appropriate internal slots. Finally, we callsettings_to_environment()when we need to access those slots (or we use standard accessors like@type_draw.