You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The function add_stat_label() unfortunately affects all statistics and not just the ones that the user wants to update. This was particularly annoying for dichotomous and categorical variables because changing the labels in a continuous2 type would then force a label change to add the n (%) to everything else.
In previous versions of gtsummary, we were able to work around this by setting the new label to NA_character_ and the output would look like nothing had changed for the dichotomous and categorical variables. Unfortunately this trick no longer works in version 2.0.1.
tmp<-data.frame(
A= c(TRUE, TRUE, TRUE, FALSE),
B= c(TRUE, FALSE, FALSE, FALSE),
C= rnorm(4),
D= c('G1','G2','G1','G2')
)
# Default behavior for logical or categorical is to suppress the n (%)# in favor of the footertmp|>gtsummary::tbl_summary(
type=list(C~'continuous2'),
statistic=list(
gtsummary::all_continuous2() ~ c('{N_obs}','{mean} ({sd})')
)
)
# When we add the custom statistics label for continuous2 variables# the n (%) now shows up on in the variable labelstmp|>gtsummary::tbl_summary(
type=list(C~'continuous2'),
statistic=list(
gtsummary::all_continuous2() ~ c('{N_obs}','{mean} ({sd})')
)
) |>gtsummary::add_stat_label(
list(
gtsummary::all_continuous2() ~ c('Number of Subjects', 'Mean (Std Dev)')
),
location='row'
)
# In previous versions of gtsummary, the solution was to set# the label for dichotomous or categorical variables to# `NA_character_`, but that no longer workstmp|>gtsummary::tbl_summary(
type=list(C~'continuous2'),
statistic=list(
gtsummary::all_continuous2() ~ c('{N_obs}','{mean} ({sd})')
)
) |>gtsummary::add_stat_label(
list(
gtsummary::all_continuous2() ~ c('Number of Subjects', 'Mean (Std Dev)'),
gtsummary::all_dichotomous() ~NA_character_
),
location='row'
)
# Passing an empty string sort-of works, but leaves an obnoxious# comma tmp|>gtsummary::tbl_summary(
type=list(C~'continuous2'),
statistic=list(
gtsummary::all_continuous2() ~ c('{N_obs}','{mean} ({sd})')
)
) |>gtsummary::add_stat_label(
list(
gtsummary::all_continuous2() ~ c('Number of Subjects', 'Mean (Std Dev)'),
gtsummary::all_dichotomous() ~''
),
location='row'
)
Ideally, the merge would be acting more like gt::cols_merge() where the pattern cols_merge_pattern = "{label}, {stat_label}" could be replaced with cols_merge_pattern = "{label}<<, {stat_label}>>" and updated labels that are NA will work.
The text was updated successfully, but these errors were encountered:
Thank you so much for responding to this. I've checked that the reprex example works and I've been successful using gtsummary version 2.0.1.9008 in my code stack.
The function add_stat_label() unfortunately affects all statistics and not just the ones that the user wants to update. This was particularly annoying for dichotomous and categorical variables because changing the labels in a continuous2 type would then force a label change to add the n (%) to everything else.
In previous versions of gtsummary, we were able to work around this by setting the new label to
NA_character_
and the output would look like nothing had changed for the dichotomous and categorical variables. Unfortunately this trick no longer works in version 2.0.1.Ideally, the merge would be acting more like gt::cols_merge() where the pattern
cols_merge_pattern = "{label}, {stat_label}"
could be replaced withcols_merge_pattern = "{label}<<, {stat_label}>>"
and updated labels that are NA will work.The text was updated successfully, but these errors were encountered: