From d3bb20a1b6cf994da3ea461e583f1e7fd8bf18d9 Mon Sep 17 00:00:00 2001 From: Marc Heinrich Date: Thu, 12 Feb 2026 16:00:48 +0100 Subject: [PATCH] Fix argument droplevels=FALSE ignored for table.formula When calling function table1(), the argument droplevels=FALSE had no effect. The issue was introduced in c0a31d2 where lapply(m2, as.factor) was replaced by lapply(m2, factorp). The first one preserves the levels of the original columns, while the second does not. --- R/table1.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/table1.R b/R/table1.R index 46873f1..5a1085e 100644 --- a/R/table1.R +++ b/R/table1.R @@ -1513,7 +1513,7 @@ table1.formula <- function(x, data, overall="Overall", rowlabelhead="", transpos if (any(sapply(m2, function(xx) any(is.na(xx))))) { stop("Stratification variable(s) should not contain missing values.") } - m2 <- lapply(m2, factorp) + m2 <- lapply(m2, function(x) factorp(x, levels = levels(x))) if (droplevels) { m2 <- lapply(m2, droplevels) }