-
Notifications
You must be signed in to change notification settings - Fork 209
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
Draft: specs and vctrs support #862
base: master
Are you sure you want to change the base?
Conversation
Hi @krlmlr, this is a really cool idea. We were already thinking that we should eventually refactor the formatting functions so that other table packages (like {rtables}) could take advantage of them, but your proposal goes much further in including non-table packages like ggplot2. Two questions for you:
|
Thanks for the heads up. Home for this codeMy initial thought was to keep this code in gt, but there is some advantage in putting it into a separate package. We could move to {pillar}, but that package brings in dependencies which might put off dependency-aware users -- this contradicts the idea of making the formatters easy to use for other users. I'm not sure we want it in {vctrs} either. So the options seem to be: gt or a new package, perhaps {fmts}, depending only on {vctrs} (and maybe even only suggesting it)? If we consider a separate package, scope, extensibility, and back-compatibility becomes relevant. We could also consider starting the work in gt, perhaps without exporting the new code. ScopeFor this package to be useful "out of the box" to other table formatters, I think it should target HTML, LaTeX, RTF, plain, VT100, and ggplot2 directly. New important targets would have to be added and maintained in that package. It is possible to change the way how the formatting is done to use a form of double dispatch, which we can simulate with 2x single dispatch until R7 is available. Because the number of targets is finite and very small, we would dispatch over the target first and then over the spec. This feels a bit over-engineered to me for this particular problem. ExtensibilityWith the proposed approach, it is possible to create a derived spec that supports a new format by wrapping it. Extending a spec to add detail to how numbers are printed is difficult though. To effectively support even the initial target formats, we might consider a new DSL that specifies, in a target-agnostic way, how numbers are to be formatted. Ideally we could use a single expression in this DSL to define the format of a number and then render it to all targets using the same expression. Do you feel that such a DSL is feasible for all the formats that gt currently supports? Back-compatibilityChanges in the formats should not break gt or other packages. We could use the concept of "editions" similarly to what testthat and dbplyr already do. Incremental approachKeeping the specs in {gt} leads to much quicker results and more room for experimentation. We could implement here and mark as experimental, or even avoid exporting. |
This is a very basic sketch for extracting the formatting logic out of the
fmt_()
into first-class objects.The idea is to support the following workflow:
Reference:
Remaining work:
gt_vctr()
gt_vctr()
can check.gt_spec_()
functions, watch out for open PRs"gt_vctr"
pillar::num()
, units package, ...Created on 2022-01-12 by the reprex package (v2.0.1)