-
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
Enable passing named vector of analysis_decimals to summary.gs_design() #403
Conversation
6af9f81
to
1cc78d8
Compare
In order to support both the new (named We could simplify this code if we broke backwards compatibility. I don't know how widely these arguments are currently used. But if we want maximum flexibility, I don't think there are ways around if-else statements. |
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.
Hi @jdblischak , thanks for perfecting the summary
function. There are lots of work!
I have 2 comments.
-
When I run the example in line 236 (see https://github.com/jdblischak/gsDesign2/blob/summary-gt-decimals/R/summary.R#L236) followed by
as_gt()
, I got an error message below.
-
Can you provide the default
analysis_vars = ...
,analysis_decimals = ...
,col_vars = ...
,col_decimals = ...
? I guess these default may help users who are interested in changing only part of valuable's digits. For example, the user may only want to change theinfo_frac
valuable for 4 decimals, and keep the rest of the valuables the same decimals as the default.
I am able to reproduce this error. However, I am also able to reproduce the error when building the package from the main branch. In other words, this bug was already merged. I will investigate further to determine how to fix it.
That is a longer term goal. The default values depend on the |
Thanks for the explanations. I agree with you on item 2, where we could build another PR in the future. For item 1, will you fix the error in a new PR? If so, would you like me to get this PR merged first? |
That will depend on the fix. I went back a whole month ago, and the error was still there, which seems suspicious. Once I figure it out, I'll propose how to handle this PR in relation to the fix. |
Sounds great, thanks! |
I figured it out. There is no bug. It's a namespace problem. Both {gsDesign2} and {gsDesign} define the function library("gsDesign2")
search()[1:2]
## [1] ".GlobalEnv" "package:gsDesign2"
environment(as_gt)
## <environment: namespace:gsDesign2>
x_ahr <- gs_design_ahr()
x_ahr |> summary() |> as_gt()
library("gsDesign")
##
## Attaching package: ‘gsDesign’
##
## The following objects are masked from ‘package:gsDesign2’:
##
## as_gt, as_rtf
search()[1:3]
## [1] ".GlobalEnv" "package:gsDesign" "package:gsDesign2"
environment(as_gt)
## <environment: namespace:gsDesign>
x_ahr |> summary() |> as_gt()
## Error in UseMethod("as_gt") :
## no applicable method for 'as_gt' applied to an object of class "c('non_binding', 'ahr', 'gs_design', 'grouped_df', 'tbl_df', 'tbl', 'data.frame')" The example code is actually already written in the correct order, so there is nothing to be done. I assume we both got the error because we built the dev version of {gsDesign2} prior to running the example code interactively, thus causing {gsDesign2} to be loaded first. I confirmed I could run the examples through Lines 158 to 162 in 2cc2c73
Since this namespace conflict is unrelated to the changes I made in this PR, if you approve, please go ahead and merge. |
Thanks for efficiently figuring it out. Nice lesson to learn! |
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 !
Closes #388
This is a work-in-progress. I want to confirm the new behavior before I clean up the code, add tests, and update the documentation (and also apply analogous updates to
col_vars
andcol_decimals
).I've updated the behavior of the argument
analysis_decimals
tosummary.gs_design()
to accept a named vector. This enables the user to specifically adjust the number of displayed decimals places for specific variables without having to also include the default values for all the other analysis variables. However, I've also maintained the old behavior.Here is how it currently functions with this PR: