-
Notifications
You must be signed in to change notification settings - Fork 8
Big refactor to simplify S3 classes #584
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
Conversation
yihui
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a minor feedback. I think this is all great! Thanks!
|
|
||
| ans <- gt::gt(x) |> | ||
| gt::tab_header(title = title %||% fd_title(method)) | ||
| if (!isFALSE(footnote)) ans <- ans |> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously we could disable the footnote via footnote = FALSE. Now we wouldn't if this if statement is removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Fixed by c8609a1
| #' as_gt() | ||
| as_gt.fixed_design <- function(x, title = NULL, footnote = NULL, ...) { | ||
| method <- fd_method(x) | ||
| as_gt.fixed_design_summary <- function(x, title = NULL, footnote = NULL, ...) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it's worth exposing the true defaults here, i.e.,
| as_gt.fixed_design_summary <- function(x, title = NULL, footnote = NULL, ...) { | |
| as_gt.fixed_design_summary <- function(x, title = attr(x, "title"), footnote = attr(x, "footnote"), ...) { |
Two benefits are: 1) it'd be more transparent; 2) it'd make it possible to actually use NULL. The footnote = FALSE mentioned below was a hack that I resorted to because in the Shiny app I did need to disable the footnote. Although the natural choice was footnote = NULL, it just couldn't work because we override the NULL value by our defaults.
I don't have strong opinions on this, so if you prefer the current way, that will be fine to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your proposal, but I don't want to introduce any API changes in this already large PR. Thus for now I am following the documented interface:
Line 150 in 936ec20
| #' the table. To disable footnotes, use `footnote = FALSE`. |
But given that you were the one that introduced the workaround footnote = FALSE (#514), please feel free to send a follow-up PR to adjust this behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I'll follow up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided not to change this after looking at as_gt.gs_design_summary, in which the footnote logic was more complicated than that in as_gt.fixed_design_summary. Let's continue to use footnote = FALSE as the only way to disable footnotes.
830ccba to
c8609a1
Compare
jdblischak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @yihui! I restored the behavior of as_gt(footnote = FALSE) and added some test cases, but I decided against changing the function interface in this PR
|
|
||
| ans <- gt::gt(x) |> | ||
| gt::tab_header(title = title %||% fd_title(method)) | ||
| if (!isFALSE(footnote)) ans <- ans |> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Fixed by c8609a1
| #' as_gt() | ||
| as_gt.fixed_design <- function(x, title = NULL, footnote = NULL, ...) { | ||
| method <- fd_method(x) | ||
| as_gt.fixed_design_summary <- function(x, title = NULL, footnote = NULL, ...) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your proposal, but I don't want to introduce any API changes in this already large PR. Thus for now I am following the documented interface:
Line 150 in 936ec20
| #' the table. To disable footnotes, use `footnote = FALSE`. |
But given that you were the one that introduced the workaround footnote = FALSE (#514), please feel free to send a follow-up PR to adjust this behavior.
Closes #457
Closes #497
This PR finalizes the proposal I introduced in #497. The long-term goal is to unblock Issues like #392, which will be easily solvable after this PR has been merged.
I overhauled the S3 classes according to the following principles:
summary()returns the same class)Some decisions I made that should be reviewed:
designto the returned list, just like the fixed designs dogs_X_npe()functions. I don't fully understand why, but their structure is different than the othersgs_update_ahr()to add the attributeupdated_design = TRUEinstead of adding a class"updated_design"(following the principles above, there is no corresponding method). However, I'm not sure this is really necessary. Do we really need this information? I couldn't find anywhere in {gsDesign2} or {simtrial} where the class was queried for"updated_design""non_binding"which has no corresponding methods, I added an attributebindingthat gets passed the input argumentbinding, and is thusTRUEorFALSEto_integer()mostly untouched. The engineer in me wanted to pull apart and refactor this as well (which I actually did in a different branch), but I felt the elegance of having an S3to_integer()method for each design method didn't outweigh the improvements of removing the methods from the class hierarchy