-
Notifications
You must be signed in to change notification settings - Fork 8
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
Hide the input parameters from a design object #392
Comments
I guess you would just need a |
We can use an S3 print method to suppress printing the list element library("gsDesign2")
x <- gs_design_ahr()
class(x)
## [1] "non_binding" "ahr" "gs_design" "list"
names(x)
## [1] "input" "enroll_rate" "fail_rate" "bound" "analysis"
x <- gs_power_ahr(lpar = list(sf = gsDesign::sfLDOF, total_spend = 0.1))
class(x)
## [1] "non_binding" "ahr" "gs_design" "list"
names(x)
## [1] "input" "enroll_rate" "fail_rate" "bound" "analysis"
x <- fixed_design_ahr(
alpha = .025, power = .9,
enroll_rate = define_enroll_rate(duration = 18, rate = 1),
fail_rate = define_fail_rate(
duration = c(4, 100),
fail_rate = log(2) / 12,
hr = c(1, .6),
dropout_rate = .001
),
study_duration = 36
)
class(x)
## [1] "fixed_design" "list"
names(x)
## [1] "input" "enroll_rate" "fail_rate" "analysis" "design"
x <- gs_design_npe()
class(x)
## [1] "tbl_df" "tbl" "data.frame"
x <- gs_design_wlr()
class(x)
## [1] "non_binding" "wlr" "gs_design" "list"
names(x)
## [1] "input" "enroll_rate" "fail_rate" "bounds" "analysis" |
However, while implementing the S3 method, I ran into a problem. The output from the In general, why are we sharing so many classes between objects with very different structures? This already allows for some non-sensical possibilities. For example, if you run Below demonstrates how we are assigning the same classes to both the original list object as well as its summarized tibble object. x_gs <- gs_design_ahr()
class(x_gs)
## [1] "non_binding" "ahr" "gs_design" "list"
class(summary(x_gs))
## [1] "non_binding" "ahr" "gs_design" "grouped_df" "tbl_df" "tbl"
## [7] "data.frame"
x_fs <- fixed_design_ahr(
alpha = .025, power = .9,
enroll_rate = define_enroll_rate(duration = 18, rate = 1),
fail_rate = define_fail_rate(
duration = c(4, 100),
fail_rate = log(2) / 12,
hr = c(1, .6),
dropout_rate = .001
),
study_duration = 36
)
class(x_fs)
## [1] "fixed_design" "list"
class(summary(x_fs))
## [1] "fixed_design" "ahr" "tbl_df" "tbl" "data.frame" I think one issue we are running into is that S3 is single dispatch. In other words, it can only choose a method based on a single class. It would be nice if we could have a summary method for objects with class At minimum, I think we need to differentiate between objects that are essentially lists versus data frames, eg maybe |
@jdblischak We should stick to S3. The summary return objects should not have the same class as the design objects - I'm talking about the critical one for method dispatching. If you look at fit <- lm(1 ~ 1)
class(fit)
#> [1] "lm"
class(summary(fit))
#> [1] "summary.lm" So the solution is simple: revisit how those classes got assigned and correct them. |
I realized this was incorrect, so I want to clarify. Single versus multiple dispatch refers how many objects can influence the method dispatch. For example, in the hypothetical function call With that out of the way, back to the strategy of assigning multiple classes to a single object. class(gsDesign2::gs_design_ahr())
## [1] "non_binding" "ahr" "gs_design" "list" Only a single classed method will be dispatched, so why assign multiple classes? Because that way you can fall back to use methods for later classes. For example, you can define methods(class = "list")
## [1] all.equal as.data.frame as_tibble cbind2 coerce kronecker
## [7] Ops rbind2 relist type.convert within
## see '?methods' for accessing help and source code Looking at the package Lines 3 to 10 in 48a165b
Thus the other classes like Lines 82 to 87 in 48a165b
I'll continue to investigate how classses/methods are used in the package currently and then propose an overhaul. This should help address not only this Issue but also the refactoring of the S3 methods for |
The current design object generated by
gs_design_ahr
,gs_power_ahr
, etc., includes a lengthy list of input parameters that users may not find of interest. Is it possible to hide these input parameters?The text was updated successfully, but these errors were encountered: