tern
tern copied to clipboard
[Feature Request]: Specify format for predefined row
Feature description
We are using summarize_colvars() (but the question is the same if we are using summarize()) after splitting by rows with split_rows_by(). We would like to have different degree of precision (different formats) depending on the row. E.g. in the example below, the code:
dta_test <- data.frame(
USUBJID = rep(1:6, each = 3),
PARAMCD = rep("lab", 6 * 3),
AVISIT = rep(paste0("V", 1:3), 6),
ARM = rep(LETTERS[1:3], rep(6, 3)),
AVAL = c(9:1, rep(NA, 9)),
CHG = c(1:9, rep(NA, 9))
)
basic_table() %>%
split_cols_by("ARM") %>%
split_rows_by("AVISIT") %>%
split_cols_by_multivar(vars = c("AVAL", "CHG")) %>%
summarize_colvars(
.stats = c("n", "mean_sd"),
.formats = c("mean_sd" = "xx.x, xx.x"),
.labels = c(n = "n", mean_sd = "Mean, SD")
) %>%
build_table(dta_test)
returns
A B C
AVAL CHG AVAL CHG AVAL CHG
—————————————————————————————————————————————————————————————————
V1
n 2 2 1 1 0 0
Mean, SD 7.5, 2.1 2.5, 2.1 3.0, NA 7.0, NA NA NA
V2
n 2 2 1 1 0 0
Mean, SD 6.5, 2.1 3.5, 2.1 2.0, NA 8.0, NA NA NA
V3
n 2 2 1 1 0 0
Mean, SD 5.5, 2.1 4.5, 2.1 1.0, NA 9.0, NA NA
But what if we want more precision for one of V1, V2 or V3 (for instance if they represent the result of tests with different degree of precision). E.g
A B C
AVAL CHG AVAL CHG AVAL CHG
—————————————————————————————————————————————————————————————————
V1
n 2 2 1 1 0 0
Mean, SD 7.53, 2.12 2.53, 2.11 3.01, NA 7.00, NA NA NA # here the precision (format is different)
V2
n 2 2 1 1 0 0
Mean, SD 6.5, 2.1 3.5, 2.1 2.0, NA 8.0, NA NA NA
V3
n 2 2 1 1 0 0
Mean, SD 5.5, 2.1 4.5, 2.1 1.0, NA 9.0, NA NA
originally posted at https://github.com/Roche/rtables/issues/479
Code of Conduct
- [X] I agree to follow this project's Code of Conduct.
Contribution Guidelines
- [X] I agree to follow this project's Contribution Guidelines.
Security Policy
- [X] I agree to follow this project's Security Policy.
feature request: in some tables (like change from baseline analysis, different lab parameters should have different formats, as the values have different scales.
rtables team provided a complicated solution with analysis functions using split context argument (which is too complicated for users).
I suggest we create a wrapper to do the following: accept a list of formats, each element corresponds to a format. In the analysis function, that list of formats will be used to map the formats for each parameter (and if not exist, use the default 'xx.xx' or NULL?). This function will be similar to summarize_colvars
@BFalquet is testing if the solution provided by rtables team is working. He will follow up when there are updates
in lbt06 template we use some kind of precisions to handle it.