From 37e1ed0235bb423eb4762140fa2f32d747c6f09c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Th=C3=A9riault?= <13123390+rempsyc@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:43:03 -0500 Subject: [PATCH] put back datawizard::data_unite and use alternative trick to match order --- R/report_sample.R | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/R/report_sample.R b/R/report_sample.R index 37f21689..761a1cd2 100644 --- a/R/report_sample.R +++ b/R/report_sample.R @@ -177,8 +177,20 @@ report_sample <- function(data, # for more than one group, fix column names. we don't want "a.b (n=10)", # but rather ""a, b (n=10)"" if (length(by) > 1) { - group_names <- gsub("[.]", ", ", names(result)) - result <- stats::setNames(result, group_names) + old_names <- datawizard::data_unite( + unique(groups), + new_column = ".old_names", + separator = "." + )[".old_names"] + + new_names <- datawizard::data_unite( + unique(groups), + new_column = ".new_names", + separator = ", " + )[".new_names"] + + name_map <- stats::setNames(new_names[[1]], old_names[[1]]) + names(result) <- name_map[names(result)] } # remember values of first columns variable <- result[[1]]["Variable"]