-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
[Feature Request]: format_xx not to drop 0 after rounding #1351
Comments
Hi @pzhang-cims, This format is not currently available as a preset in library(dplyr)
library(rtables)
library(tern)
format_fixed_dp <- function(x, ...) {
if (any(is.na(x))) {
"NA"
} else if (x[1] == 0) {
"0"
} else {
sprintf("%.1f (%.2f)", x[1], x[2])
}
}
lyt<-
basic_table()%>%
split_cols_by(var= 'ARM')%>%
analyze_vars(vars='AGE',
.stats = c("mean_sd"),
.formats = c(
"mean_sd" = format_fixed_dp
),
.labels = c(
"mean_sd" = "Mean (SD)"
)
)
build_table(lyt,pharmaverseadam::adsl)
#> Placebo Xanomeline High Dose Xanomeline Low Dose Screen Failure
#> —————————————————————————————————————————————————————————————————————————————————————
#> Mean (SD) 75.2 (8.59) 74.4 (7.89) 75.7 (8.29) 75.1 (9.70) Created on 2024-11-07 with reprex v2.1.1 |
@edelarua thank you so much for the quick response! this really helps and i tried from my end it work! |
You're welcome! Closing this issue now. |
dear @pzhang-cims , could you please share this question to https://stackoverflow.com/questions/tagged/nest-tern, and @edelarua can answer there. We would love to build the user community and better support each other in the future. Thanks a lot in advance! |
@shajoezhu and @edelarua, yes i'd love to support the community. I just post the questions there and feel free to wrap it up. https://stackoverflow.com/questions/79168575/format-xx-not-to-drop-0-after-rounding |
brilliant! thanks so much guys! |
Feature description
Hi there,
Many thanks for the development of {tern} package that we really enjoy using such package.
I would like to check with you about
format_xx()
. the format_value will have different values when utilize different codes. See belowthe "0.20" is my preferred format. The reason I asked this question is i'm using analyze_vars for the calculation and formatting.
the current
list_valid_format_labels()
in 'rtables' do not include the format "xx.x (xx.xx)" I would like to use. So I'm trying to useformat_xx
inanalyze_vars
The results will be
So i'm wondering if there is additional feature that using
tern::analyze_vars
(where I really like this function to put all the variables into the function with order), with option of.formats
to specify the format? That isformat_xx()
to not dropping 0 at the end.Code of Conduct
Contribution Guidelines
Security Policy
The text was updated successfully, but these errors were encountered: