-
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
Redirect as_gt() to gsDesign2 when it is masked by simtrial::as_gt() #287
Conversation
Surprisingly |
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.
We probably should take one step back and rethink why we need the S3 generic as_gt()
in the first place. If the answer is pretty printing of results, we may consider extending base::print()
instead just like we did with base::summary()
. The advantages are: 1) print()
ing is implicit in R, so users don't need to call it explicitly unless they want to change default argument values; 2) it exists in base R, so we don't need to define the generic but only the methods; 3) a single generic print()
won't create conflicts as two separate generics do (as_gt()
in both packages).
If we want pretty printing in R Markdown/Quarto/litedown, we'll need to define S3 methods for knitr::knit_print
and xfun::record_print
. In these methods, we can automatically determine whether we want to print the table as gt
or rtf
.
I don't understand the purpose of as_gt()
well, but from my experience, two functions with the same name in two separate packages are doomed to create trouble for both developers and users. In my eyes, dplyr::filter()
was the worst mistake in Tidyverse, and unfortunately, there's no way to completely put the worms back to the can once the can is opened (ad hoc measures exist but the confusion will last forever). That's why I'm so glad that we haven't released simtrial::as_gt
to CRAN yet.
If we really need as_gt()
, we'd better define it once in a certain "base" package (such as msdtools mentioned by Nan), and let other packages extend it.
Surprisingly
R CMD check --as-cran
does not complain about the use of:::
.
I take the credit shamelessly. Back in 2013 when I was still bold and not bald, I had a long debate with CRAN maintainers, and eventually they agreed to allow :::
for the case of packages with the same maintainer. That is, if two packages have the same maintainer, the two packages can use :::
to get unexported functions from each other. Yujie is the maintainer of both simtrial and gsDesign2, so we are free to steal internal objects from one package to another.
I just remembered another complication with using |
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, @jdblischak ! A quick question: shall we also update gsDesign2
similarly?
@LittleBeannie Yes. Already done in Merck/gsDesign2#467. Please add both of these PRs to the agenda to discuss at Friday's group meeting. Thanks! |
That's great, thank you! Will do. |
|
||
#' @export | ||
as_gt.fixed_design <- function(x, ...) { | ||
gsDesign2:::as_gt.fixed_design(x, ...) |
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.
Regarding :::
, actually I forgot to ask whether it would work by calling gsDesign::as_gt()
instead of the specific method:
gsDesign2:::as_gt.fixed_design(x, ...) | |
gsDesign2::as_gt(x, ...) |
Of course, it will be better if we could avoid using :::
.
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.
Unfortunately it doesn't work with only ::
library("gsDesign2")
library("simtrial")
## Attaching package: ‘simtrial’
##
## The following object is masked from ‘package:gsDesign2’:
##
## as_gt
##
gs_design_ahr() |> summary() |> as_gt()
## Error: 'as_gt.gs_design' is not an exported object from 'namespace:gsDesign2'
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.
Interesting. Thanks for confirming!
Closes #284
cc: @yihui
Here is my proposed solution to fix the masking of the generic
gsDesign2::as_gt()
by the genericsimtrial::as_gt()
: