Skip to content
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

Refactor as_rtf() #450

Merged
merged 44 commits into from
Aug 22, 2024
Merged

Refactor as_rtf() #450

merged 44 commits into from
Aug 22, 2024

Conversation

yihui
Copy link
Contributor

@yihui yihui commented Aug 12, 2024

Massive refactoring of as_rtf() to share code with as_gt().

R/as_rtf.R Outdated Show resolved Hide resolved
R/as_rtf.R Outdated Show resolved Hide resolved
@yihui yihui changed the title Tweaking as_rtf() Refactor as_rtf() Aug 13, 2024
@yihui yihui marked this pull request as ready for review August 13, 2024 19:34
@jdblischak
Copy link
Collaborator

xref: #282

R/as_gt.R Show resolved Hide resolved
@@ -242,115 +250,24 @@ as_gt.gs_design <- function(
display_inf_bound = FALSE,
...) {

method <- intersect(class(x), c("ahr", "wlr", "combo", "rd"))[1]
full_alpha <- attr(x, "full_alpha")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LittleBeannie I have a question regarding a difference between as_gt() and as_rtf() that I noticed while comparing the two: for as_gt(), we obtain full_alpha from the attribute of x, whereas for as_rtf(), full_alpha is its argument and not retrieved from x's attributes. Is this expected? I'm not sure if you or @elong0527 is the right person to ask.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @yihui , yes, I can answer the question. The full_alpha should be retrieved from x's attributes. I will prepare a PR to get it there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to do it, please wait until this PR is merged, or I can just do it in this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the confirmation. I know there are many changes occurring in this pull request, so let's wait until this PR is merged.

Copy link
Collaborator

@LittleBeannie LittleBeannie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @yihui, there are lots of work, thank you so much! I only have some very minor comments, regarding the naming of the utility functions.

R/as_gt.R Outdated
}

# get the fixed design method
fixed_method <- function(x) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it appropriate to refer to this as the 'fixed_design_method'? From my perspective, the term 'fixed method' implies that the method is fixed, which may have limited clinical significance.

Furthermore, I've observed utility functions for both fixed design (such as fixed_method, fixed_title, method_footnote), as well as group sequential design (such as get_display_columns , footnote_content, footnote_non_binding, footnote_row, gs_design_info). I am considering whether it would be beneficial to use distinct prefixes for these two sets of utilities to differentiate their purposes.

Finally, I am wondering if we should save the above 2 sets of utilities into a separate R file, and name it as utility_as_gt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am considering whether it would be beneficial to use distinct prefixes for these two sets of utilities to differentiate their purposes.

I'm using the prefixes fd_ and gsd_ now, and am open to other suggestions. I tend not to use the prefix gs_design_ because I noticed that we have had functions with this prefix but serve a very different purpose. I hope the abbreviations fd and gsd make sense. They are only for ourselves and users won't use them, so the naming is perhaps not critically important. Anyway, naming is really hard :)

Finally, I am wondering if we should save the above 2 sets of utilities into a separate R file, and name it as utility_as_gt.

I don't have an opinion on that. I can certainly put these functions in as_utils.R if you prefer.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the fd and gsd, which are sufficiently clear for developers. I am also good for the current folder/file structure. I will get it merged. Thanks for all the work!

R/as_gt.R Outdated
if (is.null(title)) title <- sprintf("Fixed Design %s Method", switch(
design_mtd,
# get the default title
fixed_title <- function(method) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Echo with my previous comment, can we call this function as fixed_design_title?

R/as_gt.R Outdated
if (is.null(footnote)) footnote <- switch(
design_mtd,
# get the default footnote
method_footnote <- function(x, method) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering why the prefix of fixed_ is missing... Is the method_footnote appliable for both fixed design and group sequential design?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was simply being lazy. It was only for fixed design.

@@ -242,115 +250,24 @@ as_gt.gs_design <- function(
display_inf_bound = FALSE,
...) {

method <- intersect(class(x), c("ahr", "wlr", "combo", "rd"))[1]
full_alpha <- attr(x, "full_alpha")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @yihui , yes, I can answer the question. The full_alpha should be retrieved from x's attributes. I will prepare a PR to get it there.

R/as_gt.R Outdated
}

# a list of information for `as_[gt|rtf].gs_design()` methods
gs_design_info <- function(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am hesitant to use gs_design_info as the name, as info in gsDesign2 carries a specific meaning – statistical information (1/variance). Can we consider an alternative name for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming of this function is the hardest. I spent nearly half an hour on it but couldn't think of a better name. I ended up using gsd_parts(). Please feel free to suggestion a different one.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, naming is always the hardest part. As long as we could get rid of the info as keywords, we should be good. The new name gsd_parts looks good to me.

@LittleBeannie LittleBeannie self-requested a review August 22, 2024 17:23
@LittleBeannie LittleBeannie merged commit b8b3deb into Merck:main Aug 22, 2024
7 checks passed
@yihui yihui deleted the as_rtf_tweaks branch August 22, 2024 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants