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"]